Loading...
Submission
Id When Author Problem Language CPU Memory Verdict
17831 2024-04-24 00:27:55 SajidAbdullah Help Akib!!! C++ 17 503 ms 6128 kb Accepted
Test Cases
CPU Memory Verdict
1 1 ms 3380 kb Accepted
2 1 ms 3324 kb Accepted
3 255 ms 4704 kb Accepted
4 503 ms 6128 kb Accepted
5 404 ms 5500 kb Accepted
6 4 ms 3276 kb Accepted
Source Code
program.cpp
Download
  1.  
  2.  
  3. #include<bits/stdc++.h>
  4.  
  5. #define endl "\n"
  6. #define FF ios_base::sync_with_stdio(0);cin.tie(0)
  7. #define binary(value, size) cout << bitset<size>(value) << '\n'
  8. #define Tp template<class T>
  9. #define Tpp template<typename T>
  10. #define Tppp template<typename T1,typename T2>
  11. #define eps 1e-9
  12. #define pf printf
  13. #define sf scanf
  14. #define clr(arr,val) memset((arr),val,(sizeof(arr)))
  15. #define rep(i,a,b) for(long long int i=a;i<b;i++)
  16. #define repb(i,a,b) for(long long int i=a;i>=b;i--)
  17. #define all(v) (v).begin(),(v).end()
  18. #define asort(a) sort(a.begin(),a.end())
  19. #define arev(a) reverse(a.begin(),a.end())
  20. #define F first
  21. #define S second
  22. #define pb push_back
  23. #define eb emplace_back
  24. #define pbb pop_back
  25. #define mp make_pair
  26. #define V vector
  27. #define P pair
  28. #define M map
  29. #define mt make_tuple
  30. #define BS(v,x) binary_search(v.begin(),v.end(),x) //return true /false
  31. #define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()//found and that value and not found than greater value pos
  32. #define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin() //found and greater value pos && not found also greater pos
  33. #define sma(c) towlower(c)
  34. #define rt(x) sqrt(x)
  35. #define cap(c) towupper(c)
  36. #define sq(a) ((a)*(a))
  37. #define cube(a) ((a)*(a)*(a))
  38. #define SUM(v) accumulate (v.begin(),v.end(),0)//sum of the vector
  39. #define MAX(v) *max_element(v.begin(),v.end())//max element of the vector
  40. #define MIN(v) *min_element(v.begin(),v.end())//min element of the vector
  41. #define SZ(x) long long int(x.size())
  42. #define Ceil(n) (long long int)ceil(n)
  43. #define Floor(n) (long long int)floor(n)
  44. #define deb(x) cout << #x << " = " << x << "\n";
  45. #define deb2(x,y) cout << #x << " = " << x << ", "; cout << #y << " = " << y << "\n";
  46. #define deb3(x,y,z) cout << #x << " = " << x << ", "; cout << #y << " = " << y << ", "; cout << #z << " = " << z << "\n";
  47. #define deb4(x,y,z,r) cout << #x << " = " << x << ", "; cout << #y << " = " << y << ", "; cout << #z << " = " << z << ", ";cout << #r << " = " << r << "\n";
  48. #define out(ans) cout<<ans<<"\n"
  49. #define mx 1000000
  50. #define outs(ans) cout<<ans<<" "<<"\n"
  51. #define FI freopen ("in.txt", "r", stdin)
  52. #define FO freopen ("out.txt", "w", stdout)
  53.  
  54. using namespace std;
  55.  
  56. typedef long long int ll;
  57. typedef pair<ll,ll> pll;
  58. typedef vector<ll> vll;
  59. typedef vector<pll> vpll;
  60.  
  61.  
  62.  
  63.  
  64.  
  65. class PrefixSum
  66. {
  67. private:
  68. vll pref;
  69. ll ss;
  70.  
  71. public:
  72. PrefixSum(vector<ll>const &arr)
  73. {
  74. ll n=arr.size();
  75.  
  76. pref.resize(n,0);
  77. ss=0;
  78. for(ll i=0;i<n;i++)
  79. {
  80. ss+=arr[i];
  81. pref[i]=ss;
  82. }
  83. }
  84. vll get()
  85. {
  86. return pref;
  87. }
  88. ll query(ll left, ll right)
  89. {
  90. if(left>right) return -1e18;
  91. if(left>0)
  92. {
  93. return (pref[right]-pref[left-1]);
  94. }
  95. else return pref[right];
  96. }
  97. };
  98. const ll RR=1e9-1;
  99. void S()
  100. {
  101. ll n,q;cin>>n>>q;
  102. vll v(n);
  103. rep(i,0,n)
  104. {
  105. cin>>v[i];
  106. }
  107. PrefixSum sp(v);
  108. rep(i,0,q)
  109. {
  110. ll x1,y1;cin>>x1>>y1;
  111. x1--;y1--;
  112.  
  113. ll val=sp.query(x1,y1);
  114. cout<<val<<endl;
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. }
  123.  
  124. int main()
  125. {
  126. //Go();
  127. S();
  128. return 0;
  129. }
  130.  
  131.  
  132.