fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. unsigned long long BIT[1000000],a[1000000],n;
  5. void update(int x, int val)
  6. {
  7. for(; x <= n; x += (x & -x))
  8. BIT[x] += val;
  9. }
  10. int query(int x)
  11. {
  12. int sum = 0;
  13. for(; x > 0; x -= (x & -x))
  14. sum += BIT[x];
  15. return sum;
  16. }
  17. int main()
  18. {
  19. int q;
  20. char t;
  21. cin>>n>>q;
  22. for(int i = 1;i <= n;i++){
  23. cin>>a[i];
  24. update(i,a[i]);
  25. }
  26. while(q--){
  27. cin>>t;
  28. if(t == 'S'){
  29. int a,b;
  30. cin>>a>>b;
  31. if(a == 0){
  32. x = query(b + 1);
  33. cout<<x<<endl;
  34. }
  35. else{
  36. x = query(b+1);
  37. y = query(a);
  38. cout<<(x-y)<<endl;
  39. }
  40. else if(t == 'G'){
  41. int w,x;
  42. cin>>w>>x;
  43. update(w+1,x);
  44. }
  45. else if(t == 'T'){
  46. int y,z;
  47. cin>>y>>z;
  48. update(y+1,-z);
  49. }
  50. }
  51. return 0;
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
1 2 3 4 5
S 0 4
G 0 10
S 0 4
G 0 5
S 0 4
compilation info
prog.cpp: In function 'int main()':
prog.cpp:32: error: 'x' was not declared in this scope
prog.cpp:36: error: 'x' was not declared in this scope
prog.cpp:37: error: 'y' was not declared in this scope
prog.cpp:40: error: expected `}' before 'else'
stdout
Standard output is empty