fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4. ll n,tree[1030][1030];
  5. void update(ll x,ll y,ll val)
  6. {
  7. while(x<=n+5)
  8. {
  9. ll y1=y;
  10. while(y1<=n+5)
  11. {
  12. tree[x][y1]+=val;
  13. y1+= y1 & -y1;
  14. }
  15. x+= x & -x;
  16. }
  17. }
  18. ll quary(ll x,ll y)
  19. {
  20. ll sum=0;
  21. while(x>0)
  22. {
  23. ll y1=y;
  24. while(y1>0)
  25. {
  26. sum+=tree[x][y1];
  27. y1-= y1 & -y1;
  28. }
  29. x-= x & -x;
  30. }
  31. return sum;
  32. }
  33. int main()
  34. {
  35. ll t,T,x1,x2,y1,y2,ans,val;
  36. char ch1[10];
  37. string ch;
  38. scanf("%lld",&T);
  39. for(t=1;t<=T;t++)
  40. {
  41. scanf("%lld",&n);
  42. memset(tree,0,sizeof tree);
  43. while(1)
  44. {
  45. getchar();
  46. scanf("%s",&ch1);
  47. //ch=ch1;
  48. if(ch1[1]=='E')
  49. {
  50. scanf("%lld %lld %lld",&x1,&y1,&val);
  51. ans=quary(x1+1,y1+1)-quary(x1,y1);
  52. //update(x1+1,y1+1,-ans);
  53. update(x1+1,y1+1,val-ans);
  54. }
  55. if(ch1[1]=='U')
  56. {
  57. scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);
  58. ans=quary(x2+1,y2+1)-quary(x1,y2+1)-quary(x2+1,y1)+quary(x1,y1);
  59. printf("%lld\n",ans);
  60. }
  61. if(ch1[1]=='N')
  62. break;
  63. }
  64. //if(t!=T)
  65. printf("\n");
  66. }
  67. return 0;
  68. }
  69.  
Time limit exceeded #stdin #stdout 5s 10976KB
stdin
Standard input is empty
stdout
Standard output is empty