aytdev

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

Jul 28th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. #define sp(y) fixed<<setprecision(y)
  6. #define w(t) int t;cin>>t;while(t--)
  7. #define pi 2*acos(0.0)
  8. #define bg begin()
  9. #define en end()
  10. #define all(x) x.begin(),x.end()
  11. #define sortarr(x) sort(x,x+arrsize(x))
  12. #define arrsize(x) sizeof(x)/sizeof(x[0])
  13. #define sortall(x) sort(all(x))
  14. #define formn(m,n) for(m;m<=n;m++)
  15. #define mp make_pair
  16. #define pb push_back
  17. #define vi vector<ll>
  18. #define vs vector<string>
  19. #define REP(i,a,b) for (int i=a;i<=b;i++)
  20. #define sq(a) (a)*(a)
  21. #define inparr(arr) for(auto &x: arr){cin>>x;}
  22. #define printarr(arr) for(auto x: arr){cout<<x<<" ";}
  23. #define nline "\n"
  24. //iterative
  25.  
  26. //recursive
  27. ll pow(ll c,ll d){return d==0?1:c*pow(c,d-1);}
  28. ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
  29. ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
  30. 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;}
  31. 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;}
  32. ll modinverse(ll a,ll m){ return modpoweritterative(a,m-2,m); }
  33.  
  34. //fast I/o;
  35. void fastIO(){
  36. ios_base::sync_with_stdio(false);
  37. cin.tie(NULL);
  38.  
  39. }
  40. void init_code(){
  41. fastIO();
  42. #ifdef EPSILON
  43. freopen("input.txt","r",stdin);
  44. freopen("output.txt","w",stdout);
  45. #endif
  46.  
  47. }
  48.  
  49. //solution
  50. #define mx 100005
  51. #define mod 1000000007
  52. ll sum[mx];
  53. ll rsum[mx];
  54.  
  55. void solve(){
  56. int n;
  57. cin>>n;
  58. ll arr[n];
  59. inparr(arr);
  60. for(int i=1;i<=n;i++)
  61. {
  62. sum[i]= sum[i-1]+ arr[i-1];
  63. }
  64. sortarr(arr);
  65. for(int i=1;i<=n;i++)
  66. {
  67. rsum[i]=rsum[i-1] + arr[i-1];
  68. }
  69. w(t){
  70. int a,b,c;
  71. cin>>a>>b>>c;
  72. if(a==1){
  73. cout<<sum[c]-sum[b-1]<<endl;
  74. }else{
  75. cout<<rsum[c]-rsum[b-1]<<endl;
  76. }
  77. }
  78.  
  79.  
  80. }
  81. //end solution
  82. int main(){
  83.  
  84.  
  85.  
  86. init_code();
  87. solve();
  88. return 0;
  89. }
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment