fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #define Kirlos ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  4. #define ll long long
  5. #define pb(k) push_back(k)
  6. #define fi first
  7. #define se second
  8. #define endl '\n'
  9. #define mp(x,y) make_pair(x,y)
  10. #define MOD 1000000007
  11. #define all(x) x.begin(), x.end()
  12. #define PI acos(-1)
  13. #define sin(x) sin((x)*PI/180)
  14. #define cos(x) cos((x)*PI/180)
  15. #define tan(x) tan((x)*PI/180)
  16. #define Ones(x) __builtin_popcountll(x)
  17.  
  18. using namespace std;
  19.  
  20. void solve()
  21. {
  22. int n;
  23. cin>>n;
  24. vector<int>vec(n+1);
  25. for(int i=1; i<n+1; i++)
  26. {
  27. cin>>vec[i];
  28. }
  29. vector<int>pre(n+1);
  30. for(int i=1; i<=n; i++)
  31. {
  32. pre[i]=pre[i-1]+vec[i];
  33. }
  34. int q;
  35. cin>>q;
  36. while(q--)
  37. {
  38. int l,r;
  39. cin>>l>>r;
  40. l++,r++;
  41. cout<<pre[r]-pre[l-1]<<endl;
  42. }
  43. }
  44.  
  45. int main()
  46. {
  47. Kirlos
  48. ll t;
  49. t=1;
  50. //cin>>t;
  51. while(t--)
  52. {
  53. solve();
  54. }
  55. return 0;
  56. }
Time limit exceeded #stdin #stdout 5s 2071088KB
stdin
Standard input is empty
stdout
Standard output is empty