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;
}
0 التعليقات:
إرسال تعليق