fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
  6. template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
  7.  
  8. #define fi first
  9. #define se second
  10. #define pb push_back
  11.  
  12. #define f(i, k, n, d) for (int i = k; i <= n; i += d)
  13. #define rf(i, k, n, d) for (int i = k; i >= n; i += d)
  14.  
  15. #define pb push_back
  16. #define ii pair<int, int>
  17.  
  18. #define all(x) x.begin(), x.end()
  19.  
  20. const string NAME = "SHOES";
  21.  
  22. /*** end of template ***/
  23.  
  24. const int N = 100009, mod = 1e9 + 7;
  25. const int INF=0x3f3f3f3f;
  26.  
  27. int n,a[N],q;
  28. ll T[N];
  29. void update(int x,int delta)
  30. { //ax += delta
  31. while(x <= n)
  32. {
  33. T[x] += delta;
  34. x += x & (-x); // lên cha
  35. }
  36. }
  37. ll gett(int x){ // a1 + a2 + ... a+ax
  38. ll sum = 0;
  39. while (x > 0){
  40. sum += T[x];// a[x-2^k+1]+...+a[x]
  41. x -= x & (-x);// x ve x - 2^k
  42. }
  43. return sum;
  44. }
  45. void solve() {
  46. cin >> n >> q;
  47. for(int i = 1; i <= n; i++)
  48. {
  49. cin >> a[i];
  50. update(i,a[i]);
  51. }
  52. while(q--)
  53. {
  54. int type;
  55. cin >> type;
  56. if(type == 1)
  57. {
  58. int l,r, m;
  59. cin >> l >> r; // a[l] += r;
  60. update(l,m);
  61. update(r + 1, - m);
  62. }
  63. else
  64. {
  65. int c,d; cin >> c >> d;
  66. cout << gett(d) - gett(c - 1) << '\n';
  67. }
  68. }
  69. }
  70. int main() {
  71. if(fopen((NAME + ".INP").c_str(), "r"))
  72. {
  73. freopen((NAME + ".INP").c_str(), "r", stdin);
  74. freopen((NAME + ".OUT").c_str(), "w", stdout);
  75. }
  76. ios_base::sync_with_stdio(0);
  77. cin.tie(0);
  78. cout.tie(0);
  79.  
  80.  
  81. int testcase = 1 ;
  82. //cin>>testcase;
  83.  
  84. while(testcase--) solve();
  85.  
  86. return 0;
  87. }
  88.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty