#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int MAXN = 2e5 + 7;
constexpr int BASE = 1 << 18;
constexpr ll mod = 1e9 + 7;
constexpr ll P = 7;
map<ll, bool> mapa;
int GENE[MAXN][3];
int gen[MAXN][9];
int wzorzec[MAXN];
ll TREE[BASE << 1];
ll LAZY[BASE << 1];
ll pot[BASE];
ll sumpot[BASE];
int n, q;
void generate(){
// -(A+B)
for(int i = 1; i <= n; i++)
gen[i][0] = (-(GENE[i][0] + GENE[i][1]) + 6)%3;
// -(A+C)
for(int i = 1; i <= n; i++)
gen[i][1] = (-(GENE[i][0] + GENE[i][2]) + 6)%3;
// -(B+C)
for(int i = 1; i <= n; i++)
gen[i][2] = (-(GENE[i][1] + GENE[i][2]) + 6)%3;
// (A+B-C)
for(int i = 1; i <= n; i++)
gen[i][3] = ((GENE[i][0] + GENE[i][1] - GENE[i][2]) + 6)%3;
// (A-B+C)
for(int i = 1; i <= n; i++)
gen[i][4] = ((GENE[i][0] - GENE[i][1] + GENE[i][2]) + 6)%3;
//(-A+B+C)
for(int i = 1; i <= n; i++)
gen[i][5] = ((-GENE[i][0] + GENE[i][1] + GENE[i][2]) + 6)%3;
//default
for(int i = 1; i <= n; i++){
gen[i][6] = GENE[i][0];
gen[i][7] = GENE[i][1];
gen[i][8] = GENE[i][2];
}
}
void compute(){
pot[0] = 1;
sumpot[0] = pot[0];
for(int i = 1; i <= n; i++){
pot[i] = (P*pot[i-1])%mod;
sumpot[i] = (pot[i] + sumpot[i-1])%mod;
}
}
void makehash(int v){
ll act = 0;
for(int i = 1; i <= n; i++)
act = (act + (gen[i][v]*pot[i])%mod)%mod;
mapa[act] = 1;
}
ll sum(int a, int b){
ll out = (sumpot[b] - sumpot[a-1])%mod;
while(out < 0)
out += mod;
return out;
}
void push(int v, int l, int r, int a, int b, int mid){
if(LAZY[v] >= 0){
LAZY[l] = LAZY[v];
LAZY[r] = LAZY[v];
TREE[l] = (LAZY[v]*sum(a, mid))%mod;
TREE[r] = (LAZY[v]*sum(mid+1, b))%mod;
}
LAZY[v] = -1;
}
void update(int v, int a, int b, int l, int r, ll x){
if(b < l || r < a) return;
else if(l <= a && b <= r){
TREE[v] = (x*sum(a, b))%mod;
LAZY[v] = x;
}
else{
int mid = (a+b)/2;
push(v, 2*v, 2*v+1, a, b, mid);
update(2*v, a, mid, l, r, x);
update(2*v+1, mid+1, b, l, r, x);
TREE[v] = (TREE[2*v] + TREE[2*v+1])%mod;
}
}
bool check(){
return mapa[(TREE[1]%mod)];
}
void treeinit(){
for(int i = 0; i <(BASE<<1); i++)
LAZY[i] = -1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
string str;
for(int i = 0; i <= 2; i++){
cin >> str;
for(int j = 0; j < n; j++){
int a;
if(str[j] == 'J') a = 0;
else if(str[j] == 'O') a = 1;
else a = 2;
GENE[j+1][i] = a;
}
}
generate();
compute();
treeinit();
for(int i = 0; i < 9; i++)
makehash(i);
cin >> q;
cin >> str;
for(int i = 1; i <= n; i++){
int a;
if(str[i-1] == 'J') a = 0;
else if(str[i-1] == 'O') a = 1;
else a = 2;
wzorzec[i] = a;
update(1, 0, BASE-1, i, i, a);
}
if(check()) cout << "Yes \n";
else cout << "No \n";
while(q--){
int a, b;
char c;
cin >> a >> b >> c;
ll x;
if(c == 'J') x = 0;
else if(c == 'O') x = 1;
else x = 2;
update(1, 0, BASE-1, a, b, x);
if(check()) cout << "Yes \n";
else cout << "No \n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
26824 KB |
Output is correct |
2 |
Correct |
152 ms |
27704 KB |
Output is correct |
3 |
Correct |
124 ms |
21240 KB |
Output is correct |
4 |
Correct |
141 ms |
27596 KB |
Output is correct |
5 |
Correct |
184 ms |
27848 KB |
Output is correct |
6 |
Correct |
144 ms |
27116 KB |
Output is correct |
7 |
Correct |
138 ms |
27224 KB |
Output is correct |
8 |
Correct |
190 ms |
27992 KB |
Output is correct |
9 |
Correct |
160 ms |
27764 KB |
Output is correct |
10 |
Correct |
181 ms |
29012 KB |
Output is correct |
11 |
Correct |
155 ms |
28244 KB |
Output is correct |
12 |
Correct |
147 ms |
29204 KB |
Output is correct |
13 |
Correct |
175 ms |
28244 KB |
Output is correct |
14 |
Correct |
145 ms |
29012 KB |
Output is correct |
15 |
Correct |
146 ms |
28244 KB |
Output is correct |
16 |
Correct |
157 ms |
29124 KB |
Output is correct |
17 |
Correct |
165 ms |
28460 KB |
Output is correct |
18 |
Correct |
122 ms |
19528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
26824 KB |
Output is correct |
2 |
Correct |
152 ms |
27704 KB |
Output is correct |
3 |
Correct |
124 ms |
21240 KB |
Output is correct |
4 |
Correct |
141 ms |
27596 KB |
Output is correct |
5 |
Correct |
184 ms |
27848 KB |
Output is correct |
6 |
Correct |
144 ms |
27116 KB |
Output is correct |
7 |
Correct |
138 ms |
27224 KB |
Output is correct |
8 |
Correct |
190 ms |
27992 KB |
Output is correct |
9 |
Correct |
160 ms |
27764 KB |
Output is correct |
10 |
Correct |
181 ms |
29012 KB |
Output is correct |
11 |
Correct |
155 ms |
28244 KB |
Output is correct |
12 |
Correct |
147 ms |
29204 KB |
Output is correct |
13 |
Correct |
175 ms |
28244 KB |
Output is correct |
14 |
Correct |
145 ms |
29012 KB |
Output is correct |
15 |
Correct |
146 ms |
28244 KB |
Output is correct |
16 |
Correct |
157 ms |
29124 KB |
Output is correct |
17 |
Correct |
165 ms |
28460 KB |
Output is correct |
18 |
Correct |
122 ms |
19528 KB |
Output is correct |
19 |
Correct |
321 ms |
36232 KB |
Output is correct |
20 |
Correct |
319 ms |
37856 KB |
Output is correct |
21 |
Correct |
263 ms |
38576 KB |
Output is correct |
22 |
Correct |
228 ms |
36064 KB |
Output is correct |
23 |
Correct |
251 ms |
32596 KB |
Output is correct |
24 |
Correct |
175 ms |
31312 KB |
Output is correct |
25 |
Correct |
277 ms |
39544 KB |
Output is correct |
26 |
Correct |
272 ms |
37668 KB |
Output is correct |
27 |
Correct |
298 ms |
40160 KB |
Output is correct |
28 |
Correct |
287 ms |
37700 KB |
Output is correct |
29 |
Correct |
315 ms |
39544 KB |
Output is correct |
30 |
Correct |
223 ms |
32344 KB |
Output is correct |
31 |
Correct |
338 ms |
40008 KB |
Output is correct |
32 |
Correct |
252 ms |
37080 KB |
Output is correct |
33 |
Correct |
175 ms |
31176 KB |
Output is correct |
34 |
Correct |
289 ms |
37580 KB |
Output is correct |
35 |
Correct |
283 ms |
36652 KB |
Output is correct |
36 |
Correct |
167 ms |
31260 KB |
Output is correct |
37 |
Correct |
176 ms |
31312 KB |
Output is correct |
38 |
Correct |
291 ms |
35124 KB |
Output is correct |
39 |
Correct |
231 ms |
33916 KB |
Output is correct |
40 |
Correct |
223 ms |
36756 KB |
Output is correct |
41 |
Correct |
251 ms |
27716 KB |
Output is correct |
42 |
Correct |
207 ms |
27344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
26824 KB |
Output is correct |
2 |
Correct |
152 ms |
27704 KB |
Output is correct |
3 |
Correct |
124 ms |
21240 KB |
Output is correct |
4 |
Correct |
141 ms |
27596 KB |
Output is correct |
5 |
Correct |
184 ms |
27848 KB |
Output is correct |
6 |
Correct |
144 ms |
27116 KB |
Output is correct |
7 |
Correct |
138 ms |
27224 KB |
Output is correct |
8 |
Correct |
190 ms |
27992 KB |
Output is correct |
9 |
Correct |
160 ms |
27764 KB |
Output is correct |
10 |
Correct |
181 ms |
29012 KB |
Output is correct |
11 |
Correct |
155 ms |
28244 KB |
Output is correct |
12 |
Correct |
147 ms |
29204 KB |
Output is correct |
13 |
Correct |
175 ms |
28244 KB |
Output is correct |
14 |
Correct |
145 ms |
29012 KB |
Output is correct |
15 |
Correct |
146 ms |
28244 KB |
Output is correct |
16 |
Correct |
157 ms |
29124 KB |
Output is correct |
17 |
Correct |
165 ms |
28460 KB |
Output is correct |
18 |
Correct |
122 ms |
19528 KB |
Output is correct |
19 |
Correct |
147 ms |
27220 KB |
Output is correct |
20 |
Correct |
123 ms |
21200 KB |
Output is correct |
21 |
Correct |
156 ms |
28456 KB |
Output is correct |
22 |
Correct |
129 ms |
26528 KB |
Output is correct |
23 |
Correct |
164 ms |
28496 KB |
Output is correct |
24 |
Correct |
146 ms |
27492 KB |
Output is correct |
25 |
Correct |
146 ms |
28500 KB |
Output is correct |
26 |
Correct |
135 ms |
27052 KB |
Output is correct |
27 |
Correct |
221 ms |
28624 KB |
Output is correct |
28 |
Correct |
142 ms |
27496 KB |
Output is correct |
29 |
Correct |
140 ms |
27888 KB |
Output is correct |
30 |
Correct |
133 ms |
26936 KB |
Output is correct |
31 |
Correct |
151 ms |
28752 KB |
Output is correct |
32 |
Correct |
143 ms |
28500 KB |
Output is correct |
33 |
Correct |
155 ms |
28012 KB |
Output is correct |
34 |
Correct |
145 ms |
27236 KB |
Output is correct |
35 |
Correct |
190 ms |
29012 KB |
Output is correct |
36 |
Correct |
143 ms |
28240 KB |
Output is correct |
37 |
Correct |
150 ms |
29004 KB |
Output is correct |
38 |
Correct |
183 ms |
28236 KB |
Output is correct |
39 |
Correct |
150 ms |
29240 KB |
Output is correct |
40 |
Correct |
163 ms |
28400 KB |
Output is correct |
41 |
Correct |
182 ms |
28996 KB |
Output is correct |
42 |
Correct |
142 ms |
28248 KB |
Output is correct |
43 |
Correct |
164 ms |
27992 KB |
Output is correct |
44 |
Correct |
157 ms |
28196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
26824 KB |
Output is correct |
2 |
Correct |
152 ms |
27704 KB |
Output is correct |
3 |
Correct |
124 ms |
21240 KB |
Output is correct |
4 |
Correct |
141 ms |
27596 KB |
Output is correct |
5 |
Correct |
184 ms |
27848 KB |
Output is correct |
6 |
Correct |
144 ms |
27116 KB |
Output is correct |
7 |
Correct |
138 ms |
27224 KB |
Output is correct |
8 |
Correct |
190 ms |
27992 KB |
Output is correct |
9 |
Correct |
160 ms |
27764 KB |
Output is correct |
10 |
Correct |
181 ms |
29012 KB |
Output is correct |
11 |
Correct |
155 ms |
28244 KB |
Output is correct |
12 |
Correct |
147 ms |
29204 KB |
Output is correct |
13 |
Correct |
175 ms |
28244 KB |
Output is correct |
14 |
Correct |
145 ms |
29012 KB |
Output is correct |
15 |
Correct |
146 ms |
28244 KB |
Output is correct |
16 |
Correct |
157 ms |
29124 KB |
Output is correct |
17 |
Correct |
165 ms |
28460 KB |
Output is correct |
18 |
Correct |
122 ms |
19528 KB |
Output is correct |
19 |
Correct |
321 ms |
36232 KB |
Output is correct |
20 |
Correct |
319 ms |
37856 KB |
Output is correct |
21 |
Correct |
263 ms |
38576 KB |
Output is correct |
22 |
Correct |
228 ms |
36064 KB |
Output is correct |
23 |
Correct |
251 ms |
32596 KB |
Output is correct |
24 |
Correct |
175 ms |
31312 KB |
Output is correct |
25 |
Correct |
277 ms |
39544 KB |
Output is correct |
26 |
Correct |
272 ms |
37668 KB |
Output is correct |
27 |
Correct |
298 ms |
40160 KB |
Output is correct |
28 |
Correct |
287 ms |
37700 KB |
Output is correct |
29 |
Correct |
315 ms |
39544 KB |
Output is correct |
30 |
Correct |
223 ms |
32344 KB |
Output is correct |
31 |
Correct |
338 ms |
40008 KB |
Output is correct |
32 |
Correct |
252 ms |
37080 KB |
Output is correct |
33 |
Correct |
175 ms |
31176 KB |
Output is correct |
34 |
Correct |
289 ms |
37580 KB |
Output is correct |
35 |
Correct |
283 ms |
36652 KB |
Output is correct |
36 |
Correct |
167 ms |
31260 KB |
Output is correct |
37 |
Correct |
176 ms |
31312 KB |
Output is correct |
38 |
Correct |
291 ms |
35124 KB |
Output is correct |
39 |
Correct |
231 ms |
33916 KB |
Output is correct |
40 |
Correct |
223 ms |
36756 KB |
Output is correct |
41 |
Correct |
251 ms |
27716 KB |
Output is correct |
42 |
Correct |
207 ms |
27344 KB |
Output is correct |
43 |
Correct |
147 ms |
27220 KB |
Output is correct |
44 |
Correct |
123 ms |
21200 KB |
Output is correct |
45 |
Correct |
156 ms |
28456 KB |
Output is correct |
46 |
Correct |
129 ms |
26528 KB |
Output is correct |
47 |
Correct |
164 ms |
28496 KB |
Output is correct |
48 |
Correct |
146 ms |
27492 KB |
Output is correct |
49 |
Correct |
146 ms |
28500 KB |
Output is correct |
50 |
Correct |
135 ms |
27052 KB |
Output is correct |
51 |
Correct |
221 ms |
28624 KB |
Output is correct |
52 |
Correct |
142 ms |
27496 KB |
Output is correct |
53 |
Correct |
140 ms |
27888 KB |
Output is correct |
54 |
Correct |
133 ms |
26936 KB |
Output is correct |
55 |
Correct |
151 ms |
28752 KB |
Output is correct |
56 |
Correct |
143 ms |
28500 KB |
Output is correct |
57 |
Correct |
155 ms |
28012 KB |
Output is correct |
58 |
Correct |
145 ms |
27236 KB |
Output is correct |
59 |
Correct |
190 ms |
29012 KB |
Output is correct |
60 |
Correct |
143 ms |
28240 KB |
Output is correct |
61 |
Correct |
150 ms |
29004 KB |
Output is correct |
62 |
Correct |
183 ms |
28236 KB |
Output is correct |
63 |
Correct |
150 ms |
29240 KB |
Output is correct |
64 |
Correct |
163 ms |
28400 KB |
Output is correct |
65 |
Correct |
182 ms |
28996 KB |
Output is correct |
66 |
Correct |
142 ms |
28248 KB |
Output is correct |
67 |
Correct |
164 ms |
27992 KB |
Output is correct |
68 |
Correct |
157 ms |
28196 KB |
Output is correct |
69 |
Correct |
305 ms |
35356 KB |
Output is correct |
70 |
Correct |
340 ms |
37852 KB |
Output is correct |
71 |
Correct |
169 ms |
31188 KB |
Output is correct |
72 |
Correct |
178 ms |
31504 KB |
Output is correct |
73 |
Correct |
183 ms |
31344 KB |
Output is correct |
74 |
Correct |
264 ms |
37540 KB |
Output is correct |
75 |
Correct |
178 ms |
32496 KB |
Output is correct |
76 |
Correct |
291 ms |
39688 KB |
Output is correct |
77 |
Correct |
256 ms |
36260 KB |
Output is correct |
78 |
Correct |
195 ms |
31264 KB |
Output is correct |
79 |
Correct |
167 ms |
31312 KB |
Output is correct |
80 |
Correct |
218 ms |
36592 KB |
Output is correct |
81 |
Correct |
178 ms |
32524 KB |
Output is correct |
82 |
Correct |
302 ms |
39872 KB |
Output is correct |
83 |
Correct |
240 ms |
36832 KB |
Output is correct |
84 |
Correct |
166 ms |
31316 KB |
Output is correct |
85 |
Correct |
192 ms |
31260 KB |
Output is correct |
86 |
Correct |
248 ms |
35840 KB |
Output is correct |
87 |
Correct |
308 ms |
37720 KB |
Output is correct |
88 |
Correct |
173 ms |
30500 KB |
Output is correct |
89 |
Correct |
243 ms |
36452 KB |
Output is correct |
90 |
Correct |
294 ms |
37828 KB |
Output is correct |
91 |
Correct |
177 ms |
31100 KB |
Output is correct |
92 |
Correct |
221 ms |
36832 KB |
Output is correct |
93 |
Correct |
186 ms |
31316 KB |
Output is correct |
94 |
Correct |
175 ms |
31320 KB |
Output is correct |
95 |
Correct |
170 ms |
31208 KB |
Output is correct |
96 |
Correct |
286 ms |
35016 KB |
Output is correct |
97 |
Correct |
207 ms |
35168 KB |
Output is correct |
98 |
Correct |
242 ms |
36716 KB |
Output is correct |
99 |
Correct |
258 ms |
27800 KB |
Output is correct |
100 |
Correct |
208 ms |
27356 KB |
Output is correct |