fork(2) download
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. void build_tree(ll int *a, ll int s,ll int e, ll int *tree, ll int index)
  7. {
  8. if(s==e)
  9. {
  10. tree[index] = a[s];
  11. return;
  12. }
  13. ll int mid = (s+e)/2;
  14. build_tree(a,s,mid,tree,2*index);
  15. build_tree(a,mid+1,e,tree,2*index+1);
  16. tree[index] += tree[2*index]+tree[2*index+1];
  17. return;
  18. }
  19. ll query(ll *tree,ll ss,ll se,ll qs,ll qe ,ll index)
  20. {
  21. //complete overlap
  22. if(ss>=qs and se<=qe)
  23. {
  24. return tree[index];
  25. }
  26. //No Overlap
  27. if(qe<ss || qs>se)
  28. return 0;
  29.  
  30. //partial overlap
  31. ll int mid = (ss + se)/2;
  32. ll int left = query(tree,ss,mid,qs,qe,2*index);
  33. ll int right = query(tree,mid+1,se,qs,qe,2*index+1);
  34. return left+right;
  35. }
  36. //point update
  37. void point_update(ll *tree, ll ss,ll se, ll i,ll inc,ll index)
  38. {
  39. if(i>se || i<ss)
  40. return;
  41. if(ss == se)
  42. {
  43. tree[index] += inc;
  44. return;
  45. }
  46. ll int mid = (ss + se)/2;
  47. point_update(tree,ss,mid,i,inc,2*index);
  48. point_update(tree,mid+1,se,i,inc,2*index+1);
  49. tree[index] = tree[2*index]+tree[2*index+1];
  50. return;
  51. }
  52.  
  53. void solve()
  54. {
  55. int n,q;
  56. cin>>n>>q;
  57.  
  58. ll a[n+1]={0};
  59. ll tree[4*n+1]={0};
  60.  
  61.  
  62. // for(int i=1;i<=4*n;i++)
  63. // cout<<tree[i]<<endl;
  64.  
  65. while(q--)
  66. {
  67. int nm;
  68. cin>>nm;
  69. if(nm==1)
  70. {
  71. int l,r,v;
  72. cin>>l>>r>>v;
  73. point_update(tree,0,n-1,l,v,1);
  74. point_update(tree,0,n-1,r,-v,1);
  75.  
  76. }
  77. else
  78. {
  79. int i;
  80. cin>>i;
  81. cout<<query(tree,0,n-1,0,i,1)<<endl;
  82. }
  83. }
  84.  
  85. }
  86.  
  87.  
  88. int main()
  89. {
  90. ios_base::sync_with_stdio(false);
  91. cin.tie(NULL);
  92.  
  93. ll int t=1;
  94. // cin>>t;
  95. while(t--)
  96. {
  97. solve();
  98. }
  99.  
  100. return 0;
  101. }
  102.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:58:7: error: variable-sized object may not be initialized
        ll a[n+1]={0};
             ^~~
prog.cpp:59:10: error: variable-sized object may not be initialized
        ll tree[4*n+1]={0};
                ^~~~~
2 errors generated.
stdout
Standard output is empty