求出每个点改变的次数%2就行了
参考http://blog.youkuaiyun.com/zxy_snow/article/details/6264135
可以利用二维树桩数组记录,每次更新(x1,y1),(x2+1,y2+1)(x1,y2+1)(x2+1,y1)四个点,可以发现
对应区域内的sum(x,y)的奇偶性改变,而其他区域的奇偶性不变。
如一个4*4的例子
x1=2,y1=2,x2=3,y2=3
更新(x2+1,y2+1)后
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1
更新(x1,y1)
0 0 0 0
0 1 1 1
0 1 1 1
0 1 1 2
更新(x1,y2+1)
0 0 0 0
0 1 1 2
0 1 1 2
0 1 1 3
更新(x2+1,y1)
0 0 0 0
0 1 1 2
0 1 1 2
0 2 2 4
可以看出除了覆盖区域外其他区域的奇数偶性并未改变
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int MAX = 1010;
int c[MAX][MAX];
int n;
int Lowbit(int x)
{
return x & (-x);
}
void Updata(int x,int y)
{
int i,k;
for(i=x; i<=n; i+=Lowbit(i))
for(k=y; k<=n; k+=Lowbit(k))
c[i][k]++;
}
int Get(int x,int y)
{
int i,k,sum = 0;
for(i=x; i>0; i-=Lowbit(i))
for(k=y; k>0; k-=Lowbit(k))
sum += c[i][k];
return sum;
}
int main()
{
int ncases,m;
int x1,y1,x2,y2;
char ch[2];
scanf("%d",&ncases);
while( ncases-- )
{
memset(c,0,sizeof(c));
scanf("%d%d",&n,&m);
while( m-- )
{
scanf("%s",ch);
if( ch[0] == 'C' )
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
Updata(x2+1,y2+1);
Updata(x1,y1);
Updata(x1,y2+1);
Updata(x2+1,y1);
}
else
{
scanf("%d%d",&x1,&y1);
printf("%d\n",Get(x1,y1)%2);
}
}
printf("\n");
}
return 0;
}
1568

被折叠的 条评论
为什么被折叠?



