SHARE
TWEET

codeforce - Kuriyama Mirai's Stones

jakaria_hossain Jun 16th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fast()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. #define ll long long
  5. int main()
  6. {
  7.     fast();
  8.     ll n;
  9.     cin>>n;
  10.     ll in[n+1],out[n+1],outs[n+1];
  11.     for(ll i=0;i<n;i++)
  12.     {
  13.         cin>>in[i];
  14.         outs[i]=in[i];
  15.     }
  16.     sort(outs,outs+n);
  17.     out[0]=in[0];
  18.     for(ll i=1;i<n;i++)
  19.     {
  20.         outs[i]+=outs[i-1];
  21.         out[i]=out[i-1]+in[i];
  22.        // cout<<out[i]<<" "<<outs[i]<<endl;
  23.     }
  24.     ll q, x,y,z;
  25.     cin>>q;
  26.     while(q--)
  27.     {
  28.         cin>>x>>y>>z;
  29.         y--,z--;
  30.         if(x==1)
  31.         {
  32.             if(y==0)cout<<out[z]<<endl;
  33.             else cout<<out[z]-out[y-1]<<endl;
  34.         }
  35.         else
  36.         {
  37.             if(y==0)cout<<outs[z]<<endl;
  38.             else cout<<outs[z]-outs[y-1]<<endl;
  39.         }
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top