Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define sp(y) fixed<<setprecision(y)
- #define w(t) int t;cin>>t;while(t--)
- #define pi 2*acos(0.0)
- #define bg begin()
- #define en end()
- #define all(x) x.begin(),x.end()
- #define sortarr(x) sort(x,x+arrsize(x))
- #define arrsize(x) sizeof(x)/sizeof(x[0])
- #define sortall(x) sort(all(x))
- #define formn(m,n) for(m;m<=n;m++)
- #define mp make_pair
- #define pb push_back
- #define vi vector<ll>
- #define vs vector<string>
- #define REP(i,a,b) for (int i=a;i<=b;i++)
- #define sq(a) (a)*(a)
- #define inparr(arr) for(auto &x: arr){cin>>x;}
- #define printarr(arr) for(auto x: arr){cout<<x<<" ";}
- #define nline "\n"
- //iterative
- //recursive
- ll pow(ll c,ll d){return d==0?1:c*pow(c,d-1);}
- ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
- ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
- ll modpow(ll a,ll b,ll m){if(b==0){return 1%m;}ll res = modpow(a,b/2,m);res = (res*res) %m;if(b%2==1){res = (res*a) %m;}return res;}
- ll modpoweritterative(ll a,ll n,ll m){ll ans=1;while(n>=1){if(n%2==0){a = (1ll * a * a ) %m;n/=2;}else{ans =(1ll * a * ans ) % m;n--;}}return ans;}
- ll modinverse(ll a,ll m){ return modpoweritterative(a,m-2,m); }
- //fast I/o;
- void fastIO(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- }
- void init_code(){
- fastIO();
- #ifdef EPSILON
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- }
- //solution
- #define mx 100005
- #define mod 1000000007
- ll sum[mx];
- ll rsum[mx];
- void solve(){
- int n;
- cin>>n;
- ll arr[n];
- inparr(arr);
- for(int i=1;i<=n;i++)
- {
- sum[i]= sum[i-1]+ arr[i-1];
- }
- sortarr(arr);
- for(int i=1;i<=n;i++)
- {
- rsum[i]=rsum[i-1] + arr[i-1];
- }
- w(t){
- int a,b,c;
- cin>>a>>b>>c;
- if(a==1){
- cout<<sum[c]-sum[b-1]<<endl;
- }else{
- cout<<rsum[c]-rsum[b-1]<<endl;
- }
- }
- }
- //end solution
- int main(){
- init_code();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment