-
Notifications
You must be signed in to change notification settings - Fork 0
/
loj1080.cpp
161 lines (133 loc) · 3.88 KB
/
loj1080.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//{
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cctype>
#include <cassert>
#include <ctime>
//}
//{
using namespace std;
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
//}
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define memo(a,v) memset(a,v,sizeof(a))
#define INF 1<<29
#define pf printf
#define sc scanf
typedef long long int ll_d;
char arr[100000+10];
int M[600000],times;
void built_segment_tree(int node, int u, int v)
{
if(u==v)
M[node]=0;
else
{
built_segment_tree(2*node,u,(u+v)/2);
built_segment_tree(2*node+1,(u+v)/2+1,v);
M[node] = 0;
}
}
void update(int node,int left, int right, int u, int v)
{
if(left>v||right<u)
return;
if(left>=u&&right<=v)
{
M[node]+=1;
M[node]%=2;
return;
//update(node<<1,left,mid,u,v);
//update(1+node<<1,mid+1,right,u,v);
}
else
{
int mid = (left+right)/2;
if(u<=mid)
update(node*2,left,mid,u,v);
if(v>mid)
update(1+node*2,mid+1,right,u,v);
}
//arr[node]=!arr[node];
}
void Query(int node, int left, int right, int u)
{
if(left>u||right<u)
return;
/*if(u==7)
cout<<"now : "<<node<<" "<<M[node]<<" "<<left<<" "<<right<<endl;*/
if(left==u&&right==u){
times=times+M[node];
/*if(node==25)
cout<<"enter "<<left<<" "<<right<<" "<<times<<" "<<M[node]<<endl;*/
return;
}
if(left<=u&&u<=right){
times+=M[node];
int mid = (left+right)/2;
Query(2*node,left,mid,u);
Query(2*node+1,mid+1,right,u);
return;
}
/* int mid = (left+right)/2;
Query(2*node,left,mid,u);
Query(2*node+1,mid+1,right,u);*/
}
int main()
{
int t,Case=1,u,v,n,q;
char type[2];
scanf("%d",&t);
while(t--)
{
scanf("%s",arr);
scanf("%d",&q);
n = strlen(arr);
built_segment_tree(1,0,n-1);
printf("Case %d:\n",Case++);
while(q--)
{
scanf("%s",type);times = 0;
if(type[0]=='I')
{
scanf("%d%d",&u,&v);
u--; v--;
update(1,0,n-1,u,v);
//cout<<M[4]<<" " <<M[5]<<" "<<M[6]<<" "<<M[9]<<" "<<M[13]<<" "<<M[17]<<" "<<M[20]<<" "<<M[25]<<endl;
}
else
{
//cout<<"M[25] "<<M[25]<<endl;
/*if(t==1)
{
cout<<M[4]<<" "<<M[6]<<" "<<M[9]<<" "<<M[13]<<" "<<M[20];
}
cout<<endl;*/
scanf("%d",&u);
u--;
Query(1,0,n-1,u);
//cout<<"times: "<<times<<endl;
char ans;
if(times%2) ans=(arr[u]=='0'?'1':'0');
else ans = arr[u];
printf("%c\n",ans);
}
}
}
return 0;
}