#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out(){cerr<<endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 2e5 + 10;
const int alpha = 27;
int base[2] = {313, 369}, mod[2] = {(int)1e9+7, (int)1e9+9};
int n, q, a[maxn][3], pw[maxn][2], val[maxn][3][2], seg[maxn << 2][2], lazy[maxn << 2];
int hsh[alpha][2];
bool mark[alpha];
void shift(int v, int l, int r);
void change(int v, int l, int r, int ql, int qr, int x){
//if (v == 1) debug(ql, qr, x);
if (qr <= l || r <= ql) return;
if (ql <= l && r <= qr){
// debug(l, r, x);
seg[v][0] = val[r-l][x][0];
seg[v][1] = val[r-l][x][1];
lazy[v] = x;
return;
}
shift(v, l, r);
int mid = (l + r) >> 1;
change(v << 1, l, mid, ql, qr, x);
change(v << 1 | 1, mid, r, ql, qr, x);
for (int i = 0; i < 2; i++){
seg[v][i] = (1ll * seg[v << 1][i] * pw[r-mid][i] + seg[v << 1 | 1][i]) % mod[i];
}
}
void shift(int v, int l, int r){
if (lazy[v] == -1) return;
int mid = (l + r) >> 1;
change(v << 1, l, mid, l, mid, lazy[v]);
change(v << 1 | 1, mid, r, mid, r, lazy[v]);
lazy[v] = -1;
}
bool check(){
//return MP(hsh[1][0], hsh[1][1]) == MP(seg[1][0], seg[1][1]);
for (int i = 0; i < alpha; i++){
if (mark[i] && MP(hsh[i][0], hsh[i][1]) == MP(seg[1][0], seg[1][1])){
// debug(i);
return true;
}
}
return false;
}
int main(){
memset(lazy, -1, sizeof lazy);
string s[3];
cin >> n >> s[0] >> s[1] >> s[2];
for (int j = 0; j < 3; j++){
for (int i = 1; i <= n; i++){
a[i][j] = (s[j][i-1] == 'J'? 0: (s[j][i-1] == 'O'? 1: 2));
// debug(i, j, a[i][j]);
}
}
pw[0][0] = pw[0][1] = 1;
for (int i = 1; i <= n; i++){
for (int j = 0; j < 2; j++){
pw[i][j] = 1ll * pw[i-1][j] * base[j] % mod[j];
}
}
for (int i = 1; i <= n; i++){
for (int j = 0; j < 3; j++){
for (int k = 0; k < 2; k++){
val[i][j][k] = (1ll * val[i-1][j][k] * base[k] + (j+1)) % mod[k];
}
}
}
for (int x1 = 0; x1 < 3; x1++){
for (int x2 = 0; x2 < 3; x2++){
for (int x3 = 0; x3 < 3; x3++){
if ((x1 + x2 + x3) % 3 != 1) continue;
int idx = x3 + x2 * 3 + x1 * 9;
// debug(x1, x2, x3, idx);
mark[idx] = true;
for (int i = 1; i <= n; i++){
int tmp = (a[i][0] * x1 + a[i][1] * x2 + a[i][2] * x3) % 3;
// if (x1 == 0 && x2 == 0 && x3 == 2) debug(i, tmp);
for (int j = 0; j < 2; j++){
hsh[idx][j] = (1ll * hsh[idx][j] * base[j] + (tmp+1)) % mod[j];
}
}
}
}
}
cin >> q;
string t;
cin >> t;
for (int i = 1; i <= n; i++){
int tmp = (t[i-1] == 'J'? 0: (t[i-1] == 'O'? 1: 2));
change(1, 1, n+1, i, i+1, tmp);
}
cout << (check()? "Yes\n": "No\n");
while(q--){
int l, r; char c; cin >> l >> r >> c;
int tmp = (c == 'J'? 0: (c == 'O'? 1: 2));
change(1, 1, n+1, l, r+1, tmp);
cout << (check()? "Yes\n": "No\n");
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
4640 KB |
Output is correct |
2 |
Correct |
314 ms |
4740 KB |
Output is correct |
3 |
Correct |
321 ms |
4632 KB |
Output is correct |
4 |
Correct |
295 ms |
4620 KB |
Output is correct |
5 |
Correct |
297 ms |
4752 KB |
Output is correct |
6 |
Correct |
290 ms |
4596 KB |
Output is correct |
7 |
Correct |
330 ms |
4676 KB |
Output is correct |
8 |
Correct |
308 ms |
4748 KB |
Output is correct |
9 |
Correct |
306 ms |
4700 KB |
Output is correct |
10 |
Correct |
308 ms |
4704 KB |
Output is correct |
11 |
Correct |
344 ms |
4796 KB |
Output is correct |
12 |
Correct |
329 ms |
4836 KB |
Output is correct |
13 |
Correct |
312 ms |
4780 KB |
Output is correct |
14 |
Correct |
325 ms |
4700 KB |
Output is correct |
15 |
Correct |
325 ms |
4792 KB |
Output is correct |
16 |
Correct |
326 ms |
4848 KB |
Output is correct |
17 |
Correct |
314 ms |
4704 KB |
Output is correct |
18 |
Correct |
326 ms |
4676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
4640 KB |
Output is correct |
2 |
Correct |
314 ms |
4740 KB |
Output is correct |
3 |
Correct |
321 ms |
4632 KB |
Output is correct |
4 |
Correct |
295 ms |
4620 KB |
Output is correct |
5 |
Correct |
297 ms |
4752 KB |
Output is correct |
6 |
Correct |
290 ms |
4596 KB |
Output is correct |
7 |
Correct |
330 ms |
4676 KB |
Output is correct |
8 |
Correct |
308 ms |
4748 KB |
Output is correct |
9 |
Correct |
306 ms |
4700 KB |
Output is correct |
10 |
Correct |
308 ms |
4704 KB |
Output is correct |
11 |
Correct |
344 ms |
4796 KB |
Output is correct |
12 |
Correct |
329 ms |
4836 KB |
Output is correct |
13 |
Correct |
312 ms |
4780 KB |
Output is correct |
14 |
Correct |
325 ms |
4700 KB |
Output is correct |
15 |
Correct |
325 ms |
4792 KB |
Output is correct |
16 |
Correct |
326 ms |
4848 KB |
Output is correct |
17 |
Correct |
314 ms |
4704 KB |
Output is correct |
18 |
Correct |
326 ms |
4676 KB |
Output is correct |
19 |
Correct |
679 ms |
18680 KB |
Output is correct |
20 |
Correct |
669 ms |
18672 KB |
Output is correct |
21 |
Correct |
525 ms |
17556 KB |
Output is correct |
22 |
Correct |
533 ms |
16604 KB |
Output is correct |
23 |
Correct |
411 ms |
5320 KB |
Output is correct |
24 |
Correct |
439 ms |
5272 KB |
Output is correct |
25 |
Correct |
682 ms |
18172 KB |
Output is correct |
26 |
Correct |
648 ms |
18152 KB |
Output is correct |
27 |
Correct |
643 ms |
18368 KB |
Output is correct |
28 |
Correct |
613 ms |
18416 KB |
Output is correct |
29 |
Correct |
610 ms |
18160 KB |
Output is correct |
30 |
Correct |
435 ms |
5580 KB |
Output is correct |
31 |
Correct |
610 ms |
18388 KB |
Output is correct |
32 |
Correct |
593 ms |
17580 KB |
Output is correct |
33 |
Correct |
379 ms |
5484 KB |
Output is correct |
34 |
Correct |
572 ms |
18340 KB |
Output is correct |
35 |
Correct |
481 ms |
15960 KB |
Output is correct |
36 |
Correct |
380 ms |
5512 KB |
Output is correct |
37 |
Correct |
377 ms |
5492 KB |
Output is correct |
38 |
Correct |
631 ms |
18384 KB |
Output is correct |
39 |
Correct |
531 ms |
18348 KB |
Output is correct |
40 |
Correct |
514 ms |
13168 KB |
Output is correct |
41 |
Correct |
638 ms |
18828 KB |
Output is correct |
42 |
Correct |
408 ms |
18720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
4640 KB |
Output is correct |
2 |
Correct |
314 ms |
4740 KB |
Output is correct |
3 |
Correct |
321 ms |
4632 KB |
Output is correct |
4 |
Correct |
295 ms |
4620 KB |
Output is correct |
5 |
Correct |
297 ms |
4752 KB |
Output is correct |
6 |
Correct |
290 ms |
4596 KB |
Output is correct |
7 |
Correct |
330 ms |
4676 KB |
Output is correct |
8 |
Correct |
308 ms |
4748 KB |
Output is correct |
9 |
Correct |
306 ms |
4700 KB |
Output is correct |
10 |
Correct |
308 ms |
4704 KB |
Output is correct |
11 |
Correct |
344 ms |
4796 KB |
Output is correct |
12 |
Correct |
329 ms |
4836 KB |
Output is correct |
13 |
Correct |
312 ms |
4780 KB |
Output is correct |
14 |
Correct |
325 ms |
4700 KB |
Output is correct |
15 |
Correct |
325 ms |
4792 KB |
Output is correct |
16 |
Correct |
326 ms |
4848 KB |
Output is correct |
17 |
Correct |
314 ms |
4704 KB |
Output is correct |
18 |
Correct |
326 ms |
4676 KB |
Output is correct |
19 |
Correct |
306 ms |
4976 KB |
Output is correct |
20 |
Correct |
321 ms |
5016 KB |
Output is correct |
21 |
Correct |
308 ms |
5064 KB |
Output is correct |
22 |
Correct |
278 ms |
5304 KB |
Output is correct |
23 |
Correct |
319 ms |
5576 KB |
Output is correct |
24 |
Correct |
294 ms |
5452 KB |
Output is correct |
25 |
Correct |
329 ms |
5564 KB |
Output is correct |
26 |
Correct |
307 ms |
5476 KB |
Output is correct |
27 |
Correct |
309 ms |
5568 KB |
Output is correct |
28 |
Correct |
283 ms |
5304 KB |
Output is correct |
29 |
Correct |
320 ms |
5572 KB |
Output is correct |
30 |
Correct |
280 ms |
5528 KB |
Output is correct |
31 |
Correct |
305 ms |
5572 KB |
Output is correct |
32 |
Correct |
302 ms |
5452 KB |
Output is correct |
33 |
Correct |
308 ms |
5472 KB |
Output is correct |
34 |
Correct |
293 ms |
5416 KB |
Output is correct |
35 |
Correct |
312 ms |
5580 KB |
Output is correct |
36 |
Correct |
327 ms |
5580 KB |
Output is correct |
37 |
Correct |
308 ms |
5560 KB |
Output is correct |
38 |
Correct |
309 ms |
5480 KB |
Output is correct |
39 |
Correct |
306 ms |
5576 KB |
Output is correct |
40 |
Correct |
304 ms |
5580 KB |
Output is correct |
41 |
Correct |
307 ms |
5572 KB |
Output is correct |
42 |
Correct |
336 ms |
5492 KB |
Output is correct |
43 |
Correct |
315 ms |
5484 KB |
Output is correct |
44 |
Correct |
330 ms |
5568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
4640 KB |
Output is correct |
2 |
Correct |
314 ms |
4740 KB |
Output is correct |
3 |
Correct |
321 ms |
4632 KB |
Output is correct |
4 |
Correct |
295 ms |
4620 KB |
Output is correct |
5 |
Correct |
297 ms |
4752 KB |
Output is correct |
6 |
Correct |
290 ms |
4596 KB |
Output is correct |
7 |
Correct |
330 ms |
4676 KB |
Output is correct |
8 |
Correct |
308 ms |
4748 KB |
Output is correct |
9 |
Correct |
306 ms |
4700 KB |
Output is correct |
10 |
Correct |
308 ms |
4704 KB |
Output is correct |
11 |
Correct |
344 ms |
4796 KB |
Output is correct |
12 |
Correct |
329 ms |
4836 KB |
Output is correct |
13 |
Correct |
312 ms |
4780 KB |
Output is correct |
14 |
Correct |
325 ms |
4700 KB |
Output is correct |
15 |
Correct |
325 ms |
4792 KB |
Output is correct |
16 |
Correct |
326 ms |
4848 KB |
Output is correct |
17 |
Correct |
314 ms |
4704 KB |
Output is correct |
18 |
Correct |
326 ms |
4676 KB |
Output is correct |
19 |
Correct |
679 ms |
18680 KB |
Output is correct |
20 |
Correct |
669 ms |
18672 KB |
Output is correct |
21 |
Correct |
525 ms |
17556 KB |
Output is correct |
22 |
Correct |
533 ms |
16604 KB |
Output is correct |
23 |
Correct |
411 ms |
5320 KB |
Output is correct |
24 |
Correct |
439 ms |
5272 KB |
Output is correct |
25 |
Correct |
682 ms |
18172 KB |
Output is correct |
26 |
Correct |
648 ms |
18152 KB |
Output is correct |
27 |
Correct |
643 ms |
18368 KB |
Output is correct |
28 |
Correct |
613 ms |
18416 KB |
Output is correct |
29 |
Correct |
610 ms |
18160 KB |
Output is correct |
30 |
Correct |
435 ms |
5580 KB |
Output is correct |
31 |
Correct |
610 ms |
18388 KB |
Output is correct |
32 |
Correct |
593 ms |
17580 KB |
Output is correct |
33 |
Correct |
379 ms |
5484 KB |
Output is correct |
34 |
Correct |
572 ms |
18340 KB |
Output is correct |
35 |
Correct |
481 ms |
15960 KB |
Output is correct |
36 |
Correct |
380 ms |
5512 KB |
Output is correct |
37 |
Correct |
377 ms |
5492 KB |
Output is correct |
38 |
Correct |
631 ms |
18384 KB |
Output is correct |
39 |
Correct |
531 ms |
18348 KB |
Output is correct |
40 |
Correct |
514 ms |
13168 KB |
Output is correct |
41 |
Correct |
638 ms |
18828 KB |
Output is correct |
42 |
Correct |
408 ms |
18720 KB |
Output is correct |
43 |
Correct |
306 ms |
4976 KB |
Output is correct |
44 |
Correct |
321 ms |
5016 KB |
Output is correct |
45 |
Correct |
308 ms |
5064 KB |
Output is correct |
46 |
Correct |
278 ms |
5304 KB |
Output is correct |
47 |
Correct |
319 ms |
5576 KB |
Output is correct |
48 |
Correct |
294 ms |
5452 KB |
Output is correct |
49 |
Correct |
329 ms |
5564 KB |
Output is correct |
50 |
Correct |
307 ms |
5476 KB |
Output is correct |
51 |
Correct |
309 ms |
5568 KB |
Output is correct |
52 |
Correct |
283 ms |
5304 KB |
Output is correct |
53 |
Correct |
320 ms |
5572 KB |
Output is correct |
54 |
Correct |
280 ms |
5528 KB |
Output is correct |
55 |
Correct |
305 ms |
5572 KB |
Output is correct |
56 |
Correct |
302 ms |
5452 KB |
Output is correct |
57 |
Correct |
308 ms |
5472 KB |
Output is correct |
58 |
Correct |
293 ms |
5416 KB |
Output is correct |
59 |
Correct |
312 ms |
5580 KB |
Output is correct |
60 |
Correct |
327 ms |
5580 KB |
Output is correct |
61 |
Correct |
308 ms |
5560 KB |
Output is correct |
62 |
Correct |
309 ms |
5480 KB |
Output is correct |
63 |
Correct |
306 ms |
5576 KB |
Output is correct |
64 |
Correct |
304 ms |
5580 KB |
Output is correct |
65 |
Correct |
307 ms |
5572 KB |
Output is correct |
66 |
Correct |
336 ms |
5492 KB |
Output is correct |
67 |
Correct |
315 ms |
5484 KB |
Output is correct |
68 |
Correct |
330 ms |
5568 KB |
Output is correct |
69 |
Correct |
540 ms |
19352 KB |
Output is correct |
70 |
Correct |
646 ms |
21344 KB |
Output is correct |
71 |
Correct |
400 ms |
7152 KB |
Output is correct |
72 |
Correct |
376 ms |
7156 KB |
Output is correct |
73 |
Correct |
376 ms |
7080 KB |
Output is correct |
74 |
Correct |
493 ms |
19344 KB |
Output is correct |
75 |
Correct |
373 ms |
7028 KB |
Output is correct |
76 |
Correct |
535 ms |
21308 KB |
Output is correct |
77 |
Correct |
535 ms |
19608 KB |
Output is correct |
78 |
Correct |
379 ms |
7116 KB |
Output is correct |
79 |
Correct |
380 ms |
7120 KB |
Output is correct |
80 |
Correct |
480 ms |
17972 KB |
Output is correct |
81 |
Correct |
387 ms |
7036 KB |
Output is correct |
82 |
Correct |
547 ms |
21320 KB |
Output is correct |
83 |
Correct |
532 ms |
20504 KB |
Output is correct |
84 |
Correct |
372 ms |
7132 KB |
Output is correct |
85 |
Correct |
374 ms |
7044 KB |
Output is correct |
86 |
Correct |
513 ms |
18620 KB |
Output is correct |
87 |
Correct |
576 ms |
21284 KB |
Output is correct |
88 |
Correct |
402 ms |
7060 KB |
Output is correct |
89 |
Correct |
512 ms |
19848 KB |
Output is correct |
90 |
Correct |
566 ms |
21280 KB |
Output is correct |
91 |
Correct |
404 ms |
7148 KB |
Output is correct |
92 |
Correct |
490 ms |
18412 KB |
Output is correct |
93 |
Correct |
369 ms |
7116 KB |
Output is correct |
94 |
Correct |
373 ms |
7016 KB |
Output is correct |
95 |
Correct |
450 ms |
7256 KB |
Output is correct |
96 |
Correct |
580 ms |
21068 KB |
Output is correct |
97 |
Correct |
534 ms |
21308 KB |
Output is correct |
98 |
Correct |
487 ms |
15632 KB |
Output is correct |
99 |
Correct |
657 ms |
21556 KB |
Output is correct |
100 |
Correct |
409 ms |
20720 KB |
Output is correct |