433B codeforces - Kuriyama mirais stones


433B codeforces - Kuriyama mirais stones


http://codeforces.com/problemset/problem/433/B




Solution in C++


#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
#define pii pair<int,int>

lli n,q,acc,t,id,t1,t2;
map<lli,lli> all,ord;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int nn[n];
    for(int i=0;i<n;i++)
    {
        cin>>t;
        acc+=t;
        all[i]=acc;
        nn[i]=t;
    }
    sort(nn,nn+n);
    for(int i=0;i<n;i++)ord[i]=1LL*nn[i]+1LL*ord[i-1];
    cin>>q;
    while(q-- && cin >> id >> t1 >>t2)
        cout<<((id==1)?all[t2-1]-all[t1-2]:ord[t2-1]-ord[t1-2])<<"\n";

    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق