This has solution for each query (and 1 and 2) has time complexity O(log n). In array f (of length n + 1)we will
store each query T (i , j) - we set f[i]++ and f[j + 1]--. For each card k between i and j (include i and j)
sum f[1] + f[2] + ... + f[k] will be increased for 1, for all others will be same as before
(look at the image 2.0 for clarification), so our solution will be described sum
(which is same as cumulative frequency) module 2.

鐪嬩簡榪欎箣鍚庯紝鏄笉鏄彂鐜板師鏉ヨ繕鍙互榪欐牱鍟婏紝鍛靛懙錛岃繖灝辨槸鎬濈淮杞崲浜嗭紝濡傛灉浣犲凡緇忕煡閬撹繖涓濊礬浜嗭紝閭d箞榪欑瘒鏂囩珷鍩烘湰涓嶇敤鐪嬩簡錛屽洜涓轟綘宸茬粡浼?/pre>
濂戒簡錛屾帴涓嬫潵鎴戜滑璇磋POJ榪欓鍚э紝浣犳槸涓嶆槸鍙戠幇榪欓鍜屼笂闈㈤偅涓嫳鏂囨弿榪扮殑棰樺緢鍍忓憿錛屽彧涓嶈繃榪欎釜鏄簩緇寸殑錛屾仼錛岀‘瀹烇紝鍏跺疄涓婇潰閭d釜灝辨槸
POJ_2155鐨勪竴緇寸増鏈紝濂戒簡榪欐牱璇達(dá)紝浣犲簲璇ユ噦浜嗗惂銆備笅闈㈢湅鐪嬩唬鐮佸惂(寤鴻鍏堣嚜宸辨兂鍝?錛屽啀鎻愪緵綃?a href="http://www.shnenglu.com/Files/klion/1.pdf">闆嗚璁烘枃鍚?/pre>

CODE
1
/**//*
2
ID:Klion
3
PROG:POJ_2155
4
LANG:C++
5
*/
6
#include <iostream>
7
using namespace std;
8
int n;
9
int num[1002][1002];
10
void update(int x,int y)
11

{//榪欓噷紜疄寰堝竻鍟?/span>
12
int y1;
13
while(x <= n)
14
{
15
y1 = y;
16
while(y1 <= n)
17
{
18
num[x][y1] ^= 1;
19
y1 += (y1 & -y1);
20
}
21
x += (x & -x);
22
}
23
}
24
void work(int x1,int y1,int x2,int y2)
25

{//涓昏鏄繖閲岋紝濂藉ソ鎯蟲竻妤?/span>
26
update(x1,y1);
27
update(x2+1,y1);
28
update(x1,y2+1);
29
update(x2+1,y2+1);
30
}
31
int read(int x,int y)
32

{
33
int ret=0;
34
int y1;
35
while(x > 0)
36
{
37
y1 = y;
38
while(y1 > 0)
39
{
40
ret = ((ret + num[x][y1]) & 1);
41
y1 -= (y1 & -y1);
42
}
43
x -= (x & -x);
44
}
45
ret &= 1;
46
return ret;
47
}
48
int main(void)
49

{
50
freopen("POJ_2155.in","r",stdin);
51
freopen("POJ_2155.out","w",stdout);
52
int t;
53
int x1,y1,x2,y2;
54
int x,y;
55
int l;
56
char str[2];
57
scanf("%d",&t);
58
while(t--)
59
{
60
memset(num,0,sizeof(num));
61
scanf("%d%d%*c",&n,&l);
62
for(int i = 0;i < l;i++)
63
{
64
scanf("%s",str);
65
if('Q' == str[0])
66
{
67
scanf("%d%d%*c",&x,&y);
68
printf("%d\n",read(x,y));
69
}
70
else
71
{
72
scanf("%d%d%d%d%*c",&x1,&y1,&x2,&y2);
73
work(x1,y1,x2,y2);
74
}
75
}
76
printf("\n");
77
}
78
return 0;
79
}
80