题目链接:http://poj.org/problem?id=2155
好像不管是几维都和一维原理差不多,多了一个维度也就多了一层循环而已(QAQ)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define P pair<int,int>
#define pi acos(-1)
inline int read()
{
int X=0,w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
int n,m,a[1008][1008];
int sum(int x,int y)
{
int s=0;
while(x>0)
{
int yy=y;
while(yy>0)
{
s+=a[x][yy];
yy-=yy&-yy;
}
x-=x&-x;
}
return s;
}
void add(int x,int z,int y)
{
while(x<=n)
{
int zz=z;
while(zz<=n)
{
a[x][zz]+=y;
zz+=zz&-zz;
}
x+=x&-x;
}
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
REW(a,0);
int e=n;
while(m--)
{
string b;
int q,w,e,r;
cin>>b;
if(b=="C")
{
cin>>q>>w>>e>>r;
add(q,w,1);
add(q,r+1,-1);
add(e+1,w,-1);
add(e+1,r+1,1);
}
else
{
cin>>q>>w;
cout<<sum(q,w)%2<<endl;
}
}
if(t)
{
cout<<endl;
}
}
return 0;
}