Advertisement
Green_13

ფენვიკი

Oct 26th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cmath>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <map>
  8. #include <set>
  9.  
  10. using namespace std;
  11. int n,a[1025][1025],b[2001][2001],m,l,r,s1,s,x,y,x0,yy,t,num;
  12. char st[5];
  13. void update (int x, int y, int q){
  14.     q=q-a[x][y];
  15.     a[x][y]+=q;
  16.     for (int i = x; i < n; i = (i | (i+1)))
  17.         for (int j = y; j < n; j = (j | (j+1)))
  18.             b[i][j] += q;
  19. }
  20. int sum (int x, int y){
  21.         if (x<0 || y<0 ) return 0;
  22.     int s = 0;
  23.     for (int i = x; i >= 0; i = (i & (i+1)) - 1)
  24.         for (int j = y; j >= 0; j = (j & (j+1)) - 1)
  25.             s += b[i][j];
  26.     return s;
  27. }
  28. int main()
  29. {
  30.     //freopen("input.txt","r",stdin);
  31.     //freopen("output.txt","w",stdout);
  32.     scanf("%d",&t);
  33.     for (int k=1;k<=t;k++){
  34.       for (int i=0;i<=n;i++)
  35.       for (int j=0;j<=n;j++){
  36.         a[i][j]=0;
  37.         b[i][j]=0;
  38.       }
  39.       scanf("%d",&n);
  40.       while (1){
  41.         scanf("%s",&st);
  42.         if (st[2]=='D'){puts(""); break;}
  43.         if (st[2]=='T') {
  44.                 scanf("%d",&x);
  45.                scanf("%d",&y);
  46.                scanf("%d",&num);
  47.             update(x,y,num);
  48.         }
  49.         if (st[2]=='M'){
  50.                 scanf("%d",&x0);
  51.                scanf("%d",&yy);
  52.                 scanf("%d",&x);
  53.                scanf("%d",&y);
  54.           int ans=sum(x,y)-sum(x,yy-1)-sum(x0-1,y)+sum(x0-1,yy-1);
  55.           printf("%d\n",ans);
  56.         }
  57.       }
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement