版权声明: https://blog.csdn.net/sgh666666/article/details/82659747
题意:
给定一个初始化全为0的01矩阵.有两种操作:
C: x1,y1,x2,y2 翻转矩形内的01
Q x,y 查询坐标为x,y是啥
分析:
以前写过一维的用树状数组区间更新的题. 这道题是个二维的.思想一样.
#include<algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>,;lkj
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define per(i,l,r) for(int i=(r)-1;i>=(l);i--)
const int inf = 0x3f3f3f3f;
const int maxn = 1e3+111;
int sum[maxn][maxn];
int n,m;
int lowbit(int x)xd
{
return x&(-x);
}
void add(int x,int y,int v)
{
while(x<=n)
{
int yy = y;
while(yy<=n)
{
sum[x][yy] += v;
yy += lowbit(yy);
}
x += lowbit(x);
}
}
int getsum(int x,int y)
{
int res = 0;
while(x>0)
{
int yy = y;
while(yy>0)
{
res += sum[x][yy];
yy -= lowbit(yy);
}
x -= lowbit(x);
}
return res%2;
}
int main()
{
int T;
cin>>T;
while(T--)
{
ms(sum);
cin>>n>>m;
int x1,x2,y1,y2;
rep(i,0,m)
{
getchar();
char c;
scanf("%c",&c);
if(c=='C')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
add(x1,y1,1);
add(x2+1,y1,-1);
add(x1,y2+1,-1);
add(x2+1,y2+1,1);
}
else
{
scanf("%d%d",&x1,&y1);
printf("%d\n",getsum(x1,y1));
}
}
if(T)puts("");
}
return 0;
}