记录一个菜逼的成长。。
题目链接
题目大意:
给你n*n的矩阵初始为0,有T次操作
两种操作:
1.C x1 y1 x2 y2 修改(x1,y1)到(x2,y2)的子矩阵值,即0变1,1变0
2.Q x y 查询(x,y)的值
树状数组有两种应用。跟线段树类似
1.单点修改,区间查询
2.区间修改,单点查询
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
typedef long long LL;
const int maxn = 1000 + 10;
int tree[maxn][maxn];
void change(int x,int y,int v)
{
for(int i=x; i<maxn; i+=lowbit(i))
{
for(int j=y; j<maxn; j+=lowbit(j))
{
tree[i][j]+=v;
}
}
}
LL getsum(int x,int y)
{
LL ans=0;
for(int i=x; i>0; i-=lowbit(i))
{
for(int j=y; j>0; j-=lowbit(j))
{
ans+=tree[i][j];
}
}
return ans;
}
int main()
{
int T,cas = 1;scanf("%d",&T);
while(T--){
if(cas>1)puts("");
cl(tree,0);
int n,q;scanf("%d%d",&n,&q);
char ope[4];
while(q--){
scanf("%s",ope);
if(ope[0] == 'C'){
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
change(x1,y1,1);change(x2+1,y1,1);
change(x1,y2+1,1);change(x2+1,y2+1,1);
}
else {
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",getsum(x,y) % 2);
}
}
cas++;
}
return 0;
}