fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define f first
  4. #define s second
  5. #define pp pair<ll,ll>
  6. using namespace std;
  7.  
  8. ll n;
  9. vector<ll> bit;
  10. void update(ll ind,ll incr)
  11. {
  12. while(ind<=n)
  13. {
  14. bit[ind]+=incr;
  15. ind+=(ind&(-ind));
  16. }
  17. }
  18.  
  19. ll query(ll ind)
  20. {
  21. ll ans=0;
  22. while(ind>=1)
  23. {
  24. ans+=bit[ind];
  25. ind-=(ind&(-ind));
  26. }
  27. return ans;
  28. }
  29.  
  30. int main()
  31. {
  32. ios_base::sync_with_stdio(false);
  33. cin.tie(NULL);
  34. ll t;
  35. cin>>t;
  36. while(t--)
  37. {
  38. ll nn,m;
  39. cin>>nn>>m;
  40. n=nn*nn*nn;
  41. vector<ll>ar(n+1);
  42. vector<ll>br(n+1);
  43. bit=br;
  44.  
  45. for(ll i=0;i<m;i++)
  46. {
  47. string s;
  48. cin>>s;
  49. if(s=="UPDATE")
  50. {
  51. ll x,y,z;ll w;
  52. cin>>x>>y>>z>>w;
  53. ll add=1+(x-1)*nn*nn+(y-1)*nn+(z-1);
  54. update(add,w);
  55.  
  56. }
  57. else
  58. {
  59. ll x1,y1,z1,x2,y2,z2;
  60. cin>>x1>>y1>>z1>>x2>>y2>>z2;
  61. ll add1=1+(x1-1)*nn*nn+(y1-1)*nn+(z1-1);
  62. ll add2=1+(x2-1)*nn*nn+(y2-1)*nn+(z2-1);
  63. ll ans=0;
  64. ans=query(add2)-query(add1-1);
  65. cout<<ans<<endl;
  66. }
  67. }
  68.  
  69.  
  70.  
  71. }
  72. }
Runtime error #stdin #stdout #stderr 0s 4244KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc