Test instructions: C denotes a 01 interchange within the Matrix, Q represents a single point of query.
#include <stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespacestd;Const intMAXN = ++5;#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1intN;Charcolor[maxn<<2][maxn<<2]; voidInbuildintRootintLintRintRT) {Color[root][rt]=0; if(L==R)return ; intMid= (l+r) >>1; Inbuild (Root,lson); Inbuild (Root,rson); } voidBuildintLintRintRT) {inbuild (RT,1N1); if(L==R)return ; intMid= (l+r) >>1; Build (Lson); Build (Rson); } voidDownintRootintLintRintLintRintRT) { if(Color[root][rt]) {//color[root][rt<<1]^=1; color[root][rt<<1|1]^=1;color[root<<1][rt]^=1; color[root<<1|1][rt]^=1; COLOR[ROOT][RT]=0; } if(L<=L&&R<=R)return ; intMid= (l+r) >>1; if(l<=mid) down (Root,l,r,lson); if(r>mid) down (Root,l,r,rson); } voidInupdate (intRootintLintRintLintRintRT) { if(l<=l&&r<=s) {Color[root][rt]^=1;return ; } intMid= (l+r) >>1; if(Color[root][rt]) {color[root][rt<<1] ^=1;color[root][rt<<1|1] ^=1; COLOR[ROOT][RT]=0; } if(l<=mid) Inupdate (Root,l,r,lson); if(r>mid) Inupdate (Root,l,r,rson); }voidUpdateintLintRintSintXintLintRintRT) { if(l<=l&&r<=R) {inupdate (rt,s,x,1N1);return ; } Down (Rt,s,x,1N1); intMid= (l+r) >>1; if(l<=mid) Update (L,r,s,x,lson); if(r>mid) Update (L,r,s,x,rson);}intInask (intRootintKeyintLintRintRT) { if(L==R)returnColor[root][rt]; intMid= (l+r) >>1; if(Color[root][rt]) {color[root][rt<<1] ^=1; Color[root][rt<<1|1] ^=1; COLOR[ROOT][RT]=0; } if(Key<=mid)returnInask (Root,key,lson); Else returnInask (Root,key,rson);}intAskintLintSintLintRintRT) { if(l==R) { returnInask (Rt,s,1N1); } intMid= (l+r) >>1; Down (Rt,s,s,1N1); if(L<=mid)returnAsk (L,s,lson); Else returnAsk (L,s,rson);}intMain () {intt,m; Charstr[Ten]; inta,b,c,d; CIN>>T; while(t--) {cin>>n>>m; Build (1N1); for(inti =0; i<m;i++) {scanf ("%s", str); if(str[0]=='C') {scanf ("%d%d%d%d",&a,&b,&c,&d); Update (A,C,B,D,1N1); } Else{scanf ("%d%d",&a,&b); printf ("%d\n", ask (A, B,1N1)); } } if(T) cout<<Endl; } return 0;}
Poj2155matrix Two-dimensional line segment tree