#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int N=2024;
int p[N][N],n;
int lowbit(int x)
{
return x&-x;
}
int sum(int x,int y)
{
int i,j,ret=0;
for(i=x;i>0;i-=lowbit(i))
for(j=y;j>0;j-=lowbit(j))
ret+=p[i][j];
return ret%2;
}
void add(int x,int y)
{
int i,j;
for(i=x;i<=n;i+=lowbit(i))
for(j=y;j<=n;j+=lowbit(j))
p[i][j]+=1;
}
int main()
{
int i,j,a1,a2,b1,b2,_,__;
char s[10];
scanf("%d",&__);
for(int k=1;k<=__;k++)
{
if(k!=1) printf("\n");
scanf("%d%d",&n,&_);
memset(p,0,sizeof(p));
while(_--)
{
scanf("%s",&s);
if(s[0]=='Q')
{
scanf("%d%d",&a1,&b1);
printf("%d\n",sum(a1,b1));
}
else
{
scanf("%d%d%d%d",&a1,&b1,&a2,&b2);
add(a1,b1);
add(a1,b2+1);
add(a2+1,b2+1);
add(a2+1,b1);
}
}
}
return 0;
}
poj2155 Matrix 【二维树状数组】
最新推荐文章于 2025-01-03 19:49:02 发布