标签:
Time Limit: 5000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Input
Output
Sample Input
0 4
1 1 2 3
2 0 0 2 2
1 1 1 2
1 1 2 -1
2 1 1 2 3
3
Sample Output
3
4
Source
1 /**/ 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 using namespace std; 8 const int mxn=1030; 9 int t[mxn][mxn]; 10 int s; 11 inline int lowbit(int x){return x&-x;} 12 void add(int x,int y,int v){ 13 while(x<=mxn){ 14 int tmp=y; 15 while(tmp<=mxn){t[x][tmp]+=v;tmp+=lowbit(tmp);} 16 x+=lowbit(x); 17 } 18 return; 19 } 20 int ask(int x,int y){ 21 int res=0; 22 while(x){ 23 int tmp=y; 24 while(tmp){res+=t[x][tmp];tmp-=lowbit(tmp);} 25 x-=lowbit(x); 26 } 27 return res; 28 } 29 int sum(int x1,int y1,int x2,int y2){ 30 return ask(x2,y2)+ask(x1-1,y1-1)-ask(x1-1,y2)-ask(x2,y1-1); 31 } 32 int main(){ 33 int i,j; 34 int ist,x1,y1,x2,y2; 35 int d; 36 scanf("%d%d",&ist,&s); 37 while(scanf("%d",&ist) && ist!=3){ 38 if(ist==1){ 39 scanf("%d%d%d",&x1,&y1,&d); 40 add(x1+1,y1+1,d); 41 } 42 else{ 43 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 44 printf("%d\n",sum(x1+1,y1+1,x2+1,y2+1)); 45 } 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5883407.html