# https://www.spoj.com/problems/CSUMQ/

Jul 28th, 2021
1,028
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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. int sum[mx];
53.
54.
55. void solve(){
56.      int n,m;
57.      cin>>n;
58.      int arr[n];
59.      inparr(arr);
60.      for(int i=0;i<n;++i)
61.      {
62.           if(i==0){
63.                sum[i]=arr[i];
64.           }else{
65.                 sum[i]=sum[i-1]+arr[i];
66.
67.           }
68.
69.      }
70.      cin>>m;
71.      for(int i=0;i<m;i++){
72.           int a,b;
73.           cin>>a>>b;
74.           cout<<sum[b]-sum[a-1]<<endl;
75.      }
76.
77.
78.
79. }
80. //end solution
81. int main(){
82.
83.
84.
85.      init_code();
86.      solve();
87.      return 0;
88. }
89.
90.
RAW Paste Data