标签:des style blog color os strong
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 17976 | Accepted: 6737 |
Description
Input
Output
Sample Input
1 2 10 C 2 1 2 2 Q 2 2 C 2 1 2 1 Q 1 1 C 1 1 2 1 C 1 2 1 2 C 1 1 2 2 Q 1 1 C 1 1 2 1 Q 2 1
Sample Output
1 0 0 1
#include"iostream" #include"cstdio" #include"cstring" using namespace std; const int ms=1e3+10; int map[ms][ms]; int n,m; int lowbit(int t) { return t&(-t); } void updata(int x,int y,int d) { while(x>0) { int y1=y; while(y1>0) { map[x][y1]+=d; y1-=lowbit(y1); } x-=lowbit(x); } } int getsum(int x,int y) { int sum=0; while(x<=n) { int y1=y; while(y1<=n) { sum+=map[x][y1]; y1+=lowbit(y1); } x+=lowbit(x); } return sum; } int main() { int i,j,k,t,tcase; //#ifndef oo //cout<<"dkkjdkk"<<endl; //#endif cin>>tcase; while(tcase--) { cin>>n>>m; memset(map,0,sizeof(map)); char s[5];//避免回车符的影响 否则 getchar() while(m--) { cin>>s; if(s[0]==‘C‘) { int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; updata(x2,y2,1); updata(x1-1,y2,-1); updata(x1-1,y1-1,1); updata(x2,y1-1,-1); //updata(x1-1,y1-1,1); } else if(s[0]==‘Q‘) { int x,y; cin>>x>>y; cout<<getsum(x,y)%2<<endl; } } if(tcase) cout<<endl; } return 0; }
Matrix 二维树状数组的第二类应用,布布扣,bubuko.com
标签:des style blog color os strong
原文地址:http://www.cnblogs.com/767355675hutaishi/p/3862625.html