C操作 取反 一个左上角 x1,y1 右下角x2,y2 的矩阵 0变1 1变0 ;
Q操作 输出x,y位置的值
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define cler(arr, val) memset(arr, val, sizeof(arr))
#define IN freopen ("in.txt" , "r" , stdin);
#define OUT freopen ("out.txt" , "w" , stdout);
typedef long long LL;
const int MAXN = 4001;//点数的最大值
const int MAXM = 20006;//边数的最大值
const int INF = 11521204;
const int mod=123456789;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int n,m;
int sum[MAXN][MAXN],ans;
void updatey(int x,int y1,int y2,int l,int r,int rt)
{
if(y1==l&&r==y2)
{
sum[x][rt]^=1;
return ;
}
int m=(l+r)>>1;
if(y2<=m) updatey(x,y1,y2,lson);
else if(m<y1) updatey(x,y1,y2,rson);
else
{
updatey(x,y1,m,lson);
updatey(x,m+1,y2,rson);
}
}
void updatex(int x1,int y1,int x2,int y2,int l,int r,int rt)
{
if(x1==l&&r==x2)
{
updatey(rt,y1,y2,1,n,1);
return ;
}
int m=(l+r)>>1;
if(x2<=m) updatex(x1,y1,x2,y2,lson);
else if(m<x1) updatex(x1,y1,x2,y2,rson);
else
{
updatex(x1,y1,m,y2,lson);
updatex(m+1,y1,x2,y2,rson);
}
}
void queryy(int x,int y,int l,int r,int rt)
{
ans^=sum[x][rt];
if(l==r) return ;
int m=(l+r)>>1;
if(y<=m) queryy(x,y,lson);
else queryy(x,y,rson);
}
void queryx(int x,int y,int l,int r,int rt)
{
queryy(rt,y,1,n,1);
if(l==r)
return;
int m=(l+r)>>1;
if(x<=m) queryx(x,y,lson);
else queryx(x,y,rson);
}
int main()
{
int t;
// IN;
scanf("%d",&t);
while(t--)
{
cler(sum,0);
char s[3];
scanf("%d%d",&n,&m);
while(m--)
{
int a,b,c,d;
scanf("%s",s);
if(s[0]=='C')
{
scanf("%d%d%d%d",&a,&b,&c,&d);
updatex(a,b,c,d,1,n,1);
}
else
{
ans=0;
scanf("%d%d",&a,&b);
queryx(a,b,1,n,1);
printf("%d\n",ans);
}
}
puts("");
}
return 0;
}