题目链接:http://poj.org/problem?id=2155
代码风格:www.notonlysuccess.com
题目大意:刚开始,整个矩阵为0;C操作:对一个矩阵进行0,1取反; Q操作求该点的数字是什么;
算法:二维线段树,具体自己模拟吧
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1
#define mid int m = (l + r) >> 1
int sum[4005][4005], n, T, m, ans;
void updatey(int L, int R, int l, int r, int rt, int temp)
{
if(L <= l && r <= R)
{
sum[temp][rt] = !sum[temp][rt];
return ;
}
mid ;
if(L <= m )
updatey(L, R, lson, temp);
if(m < R)
updatey(L, R, rson, temp);
}
void update(int Lx, int Ly, int Rx, int Ry, int l, int r, int rt)
{
if(Lx <= l && r <= Rx)
{
updatey(Ly, Ry, 1, n, 1, rt);
return ;
}
mid ;
if(Lx <= m)
update(Lx, Ly, Rx, Ry, lson);
if(m < Rx)
update(Lx, Ly, Rx, Ry, rson);
}
void queryy(int temp, int b, int l, int r, int rt)
{
ans ^= sum[temp][rt];
if(l == r)
{
return ;
}
mid ;
if(b <= m)
queryy(temp, b, lson);
else queryy(temp, b, rson);
}
void query(int a, int b, int l, int r, int rt)
{
queryy(rt, b, 1, n, 1);
if(l == r)
return ;
mid ;
if(a <= m)
query(a, b, lson);
else query(a, b, rson);
}
int main()
{
char op[12];
int a, b, c, d;
scanf("%d", &T);
while(T --)
{
memset(sum, 0, sizeof(sum));
scanf("%d%d", &n, &m);
while(m --)
{
scanf("%s", op);
if(op[0] == 'Q')
{
scanf("%d%d", &a, &b);
ans = 0;
query(a, b, 1, n, 1);
printf("%d\n", ans);
}
else
{
scanf("%d%d%d%d", &a, &b, &c, &d);
update(a, b, c, d, 1, n, 1);
}
}
printf("\n");
}
return 0;
}