标签:des style blog http color strong
Time Limit: 3000MS | Memory Limit: 65536K |
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
Source
1 #include<set> 2 #include<queue> 3 #include<vector> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cstring> 7 #include<iostream> 8 #include<algorithm> 9 using namespace std; 10 const int N = 1010; 11 #define Ch1 (i<<1) 12 #define Ch2 (Ch1|1) 13 #define mid(l,r) ((l+r)>>1) 14 #define For(i,n) for(int i=1;i<=n;i++) 15 #define Rep(i,l,r) for(int i=l;i<=r;i++) 16 17 struct tnodey{ 18 short l,r,mid; 19 int change; 20 }; 21 22 struct tnodex{ 23 short l,r,mid; 24 tnodey y[N<<2]; 25 }T[N<<2]; 26 int X,n,m,x1,y1,x,y,x2,y2; 27 char op; 28 29 void Buildy(int root,int l,int r,int i){ 30 T[root].y[i].l = l; T[root].y[i].r = r; T[root].y[i].mid = mid(l,r); 31 T[root].y[i].change = 0; 32 if(l==r) return; 33 Buildy(root,l,mid(l,r),Ch1); Buildy(root,mid(l,r)+1,r,Ch2); 34 } 35 36 void Buildx(int i,int l,int r){ 37 Buildy(i,1,n,1); 38 T[i].l = l; T[i].r = r; T[i].mid = mid(l,r); 39 if(l==r) return; 40 Buildx(Ch1,l,mid(l,r));Buildx(Ch2,mid(l,r)+1,r); 41 } 42 43 void Modifyy(int root,int l,int r,int i){ 44 if(l==T[root].y[i].l&&T[root].y[i].r==r){ 45 T[root].y[i].change ^= 1; 46 return; 47 } 48 if(r<=T[root].y[i].mid) Modifyy(root,l,r,Ch1);else 49 if(l>T[root].y[i].mid) Modifyy(root,l,r,Ch2);else 50 Modifyy(root,l,T[root].y[i].mid,Ch1),Modifyy(root,T[root].y[i].mid+1,r,Ch2); 51 } 52 53 void Modifyx(int i,int l,int r){ 54 if(l==T[i].l&&T[i].r==r){ 55 Modifyy(i,y1,y2,1); 56 return; 57 } 58 if(r<=T[i].mid) Modifyx(Ch1,l,r);else 59 if(l>T[i].mid) Modifyx(Ch2,l,r);else 60 Modifyx(Ch1,l,T[i].mid),Modifyx(Ch2,T[i].mid+1,r); 61 } 62 63 int queryy(int root,int i,int x){ 64 if(T[root].y[i].l==T[root].y[i].r) return T[root].y[i].change; 65 if(x<=T[root].y[i].mid) return queryy(root,Ch1,x) + T[root].y[i].change;else 66 if(x>T[root].y[i].mid) return queryy(root,Ch2,x) + T[root].y[i].change; 67 } 68 69 int queryx(int i,int x){ 70 if(T[i].l==T[i].r) return queryy(i,1,y); 71 if(x<=T[i].mid) return queryx(Ch1,x) + queryy(i,1,y);else 72 if(x>T[i].mid) return queryx(Ch2,x) + queryy(i,1,y); 73 } 74 75 76 void init(){ 77 scanf("%d%d",&n,&m); 78 Buildx(1,1,n); 79 For(i,m){ 80 scanf("\n");scanf("%c",&op); 81 if(op==‘C‘) { 82 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 83 Modifyx(1,x1,x2); 84 } 85 else { 86 scanf("%d%d",&x,&y); 87 printf("%d\n",queryx(1,x)%2); 88 } 89 } 90 printf("\n"); 91 } 92 93 int main(){ 94 scanf("%d",&X); 95 For(i,X) init(); 96 return 0; 97 }
POJ·2155·Matrix,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/kjerome/p/3816846.html