#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int V = 30;
const int N = 2e5 + 5;
int cnt = 3;
int a[V][N];
int lazy[N * 2];
int ch[V][N * 2], seg[V][N * 2];
void build(int ver, int nd, int l, int r) {
if (l == r) {
ch[ver][nd] = a[ver][l];
seg[ver][nd] = ch[ver][nd] == ch[cnt][nd];
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
build(ver, nd + 1, l, mid);
build(ver, rs, mid + 1, r);
seg[ver][nd] = (seg[ver][nd + 1] & seg[ver][rs]);
ch[ver][nd] = (ch[ver][nd + 1] == ch[ver][rs] ? ch[ver][rs] : -1);
}
void push(int nd, int l, int r) {
if (!lazy[nd]) return;
ch[cnt][nd] = lazy[nd];
for (int i = cnt; i >= 0; --i) {
seg[i][nd] = ch[i][nd] == ch[cnt][nd];
}
if (l != r) {
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
lazy[nd + 1] = lazy[nd];
lazy[rs] = lazy[nd];
}
lazy[nd] = 0;
}
void upd(int nd, int l, int r, int s, int e, int v) {
push(nd, l, r);
if (l >= s && r <= e && ch[cnt][nd] != -1) {
lazy[nd] = v;
push(nd, l, r);
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
push(rs, mid + 1, r);
upd(nd + 1, l, mid, s, e, v);
} else {
if (mid < s) {
push(nd + 1, l, mid);
upd(rs, mid + 1, r, s, e, v);
} else {
upd(nd + 1, l, mid, s, e, v);
upd(rs, mid + 1, r, s, e, v);
}
}
for (int i = 0; i <= cnt; ++i) {
seg[i][nd] = seg[i][nd + 1] & seg[i][rs];
ch[i][nd] = ch[i][nd + 1] == ch[i][rs] ? ch[i][rs] : -1;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
char c;
cin >> c;
a[i][j] = (c == 'J' ? 1 : c == 'O' ? 2 : 3);
}
}
auto merge = [&](int x, int y, int z) {
for (int i = 0; i < n; ++i) {
a[z][i] = a[x][i] == a[y][i] ? a[y][i] : a[y][i] ^ a[x][i];
}
};
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
if (i == j && j == k) {
continue;
}
merge(i, j, cnt);
merge(cnt, k, cnt);
cnt++;
}
}
}
int q;
cin >> q;
for (int i = 0; i < n; ++i) {
char c;
cin >> c;
a[cnt][i] = (c == 'J' ? 1 : c == 'O' ? 2 : 3);
}
for (int i = cnt; i >= 0; --i) {
build(i, 0, 0, n - 1);
}
bool ans = false;
for (int i = 0; i < cnt; ++i) {
ans |= seg[i][0] == 1;
}
cout << (ans ? "Yes" : "No") << '\n';
while (q--) {
int l, r;
cin >> l >> r;
--l, --r;
char c;
cin >> c;
int x = (c == 'J' ? 1 : c == 'O' ? 2 : 3);
upd(0, 0, n - 1, l, r, x);
ans = false;
for (int i = 0; i < cnt; ++i) {
ans |= seg[i][0] == 1;
}
cout << (ans ? "Yes" : "No") << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
111668 KB |
Output is correct |
2 |
Correct |
198 ms |
111796 KB |
Output is correct |
3 |
Correct |
210 ms |
111740 KB |
Output is correct |
4 |
Correct |
143 ms |
111744 KB |
Output is correct |
5 |
Correct |
141 ms |
111784 KB |
Output is correct |
6 |
Correct |
154 ms |
111988 KB |
Output is correct |
7 |
Correct |
143 ms |
111696 KB |
Output is correct |
8 |
Correct |
154 ms |
111700 KB |
Output is correct |
9 |
Correct |
160 ms |
111696 KB |
Output is correct |
10 |
Correct |
153 ms |
111736 KB |
Output is correct |
11 |
Correct |
159 ms |
111700 KB |
Output is correct |
12 |
Correct |
153 ms |
111700 KB |
Output is correct |
13 |
Correct |
157 ms |
111832 KB |
Output is correct |
14 |
Correct |
152 ms |
111700 KB |
Output is correct |
15 |
Correct |
157 ms |
111784 KB |
Output is correct |
16 |
Correct |
153 ms |
111744 KB |
Output is correct |
17 |
Correct |
157 ms |
111696 KB |
Output is correct |
18 |
Correct |
195 ms |
111684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
111668 KB |
Output is correct |
2 |
Correct |
198 ms |
111796 KB |
Output is correct |
3 |
Correct |
210 ms |
111740 KB |
Output is correct |
4 |
Correct |
143 ms |
111744 KB |
Output is correct |
5 |
Correct |
141 ms |
111784 KB |
Output is correct |
6 |
Correct |
154 ms |
111988 KB |
Output is correct |
7 |
Correct |
143 ms |
111696 KB |
Output is correct |
8 |
Correct |
154 ms |
111700 KB |
Output is correct |
9 |
Correct |
160 ms |
111696 KB |
Output is correct |
10 |
Correct |
153 ms |
111736 KB |
Output is correct |
11 |
Correct |
159 ms |
111700 KB |
Output is correct |
12 |
Correct |
153 ms |
111700 KB |
Output is correct |
13 |
Correct |
157 ms |
111832 KB |
Output is correct |
14 |
Correct |
152 ms |
111700 KB |
Output is correct |
15 |
Correct |
157 ms |
111784 KB |
Output is correct |
16 |
Correct |
153 ms |
111744 KB |
Output is correct |
17 |
Correct |
157 ms |
111696 KB |
Output is correct |
18 |
Correct |
195 ms |
111684 KB |
Output is correct |
19 |
Correct |
2053 ms |
117072 KB |
Output is correct |
20 |
Correct |
1310 ms |
118656 KB |
Output is correct |
21 |
Correct |
1047 ms |
120352 KB |
Output is correct |
22 |
Correct |
1103 ms |
120660 KB |
Output is correct |
23 |
Correct |
294 ms |
114388 KB |
Output is correct |
24 |
Correct |
296 ms |
114260 KB |
Output is correct |
25 |
Correct |
1087 ms |
120752 KB |
Output is correct |
26 |
Correct |
1249 ms |
120760 KB |
Output is correct |
27 |
Correct |
1723 ms |
120588 KB |
Output is correct |
28 |
Correct |
1650 ms |
120748 KB |
Output is correct |
29 |
Correct |
1472 ms |
120508 KB |
Output is correct |
30 |
Correct |
366 ms |
114332 KB |
Output is correct |
31 |
Correct |
1547 ms |
120916 KB |
Output is correct |
32 |
Correct |
1396 ms |
120404 KB |
Output is correct |
33 |
Correct |
319 ms |
114272 KB |
Output is correct |
34 |
Correct |
1506 ms |
120684 KB |
Output is correct |
35 |
Correct |
942 ms |
118356 KB |
Output is correct |
36 |
Correct |
305 ms |
114292 KB |
Output is correct |
37 |
Correct |
319 ms |
114776 KB |
Output is correct |
38 |
Correct |
1115 ms |
120588 KB |
Output is correct |
39 |
Correct |
354 ms |
120148 KB |
Output is correct |
40 |
Correct |
977 ms |
117968 KB |
Output is correct |
41 |
Correct |
1802 ms |
120944 KB |
Output is correct |
42 |
Correct |
143 ms |
120016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
111668 KB |
Output is correct |
2 |
Correct |
198 ms |
111796 KB |
Output is correct |
3 |
Correct |
210 ms |
111740 KB |
Output is correct |
4 |
Correct |
143 ms |
111744 KB |
Output is correct |
5 |
Correct |
141 ms |
111784 KB |
Output is correct |
6 |
Correct |
154 ms |
111988 KB |
Output is correct |
7 |
Correct |
143 ms |
111696 KB |
Output is correct |
8 |
Correct |
154 ms |
111700 KB |
Output is correct |
9 |
Correct |
160 ms |
111696 KB |
Output is correct |
10 |
Correct |
153 ms |
111736 KB |
Output is correct |
11 |
Correct |
159 ms |
111700 KB |
Output is correct |
12 |
Correct |
153 ms |
111700 KB |
Output is correct |
13 |
Correct |
157 ms |
111832 KB |
Output is correct |
14 |
Correct |
152 ms |
111700 KB |
Output is correct |
15 |
Correct |
157 ms |
111784 KB |
Output is correct |
16 |
Correct |
153 ms |
111744 KB |
Output is correct |
17 |
Correct |
157 ms |
111696 KB |
Output is correct |
18 |
Correct |
195 ms |
111684 KB |
Output is correct |
19 |
Correct |
208 ms |
111796 KB |
Output is correct |
20 |
Correct |
211 ms |
111676 KB |
Output is correct |
21 |
Correct |
162 ms |
111648 KB |
Output is correct |
22 |
Correct |
141 ms |
111696 KB |
Output is correct |
23 |
Correct |
156 ms |
111828 KB |
Output is correct |
24 |
Correct |
167 ms |
112084 KB |
Output is correct |
25 |
Correct |
162 ms |
111696 KB |
Output is correct |
26 |
Correct |
150 ms |
111700 KB |
Output is correct |
27 |
Correct |
165 ms |
112044 KB |
Output is correct |
28 |
Correct |
150 ms |
111684 KB |
Output is correct |
29 |
Correct |
164 ms |
111696 KB |
Output is correct |
30 |
Correct |
142 ms |
111796 KB |
Output is correct |
31 |
Correct |
166 ms |
111696 KB |
Output is correct |
32 |
Correct |
167 ms |
111696 KB |
Output is correct |
33 |
Correct |
171 ms |
111700 KB |
Output is correct |
34 |
Correct |
153 ms |
111624 KB |
Output is correct |
35 |
Correct |
166 ms |
111696 KB |
Output is correct |
36 |
Correct |
177 ms |
111696 KB |
Output is correct |
37 |
Correct |
169 ms |
111696 KB |
Output is correct |
38 |
Correct |
172 ms |
111828 KB |
Output is correct |
39 |
Correct |
166 ms |
111696 KB |
Output is correct |
40 |
Correct |
176 ms |
111700 KB |
Output is correct |
41 |
Correct |
167 ms |
111700 KB |
Output is correct |
42 |
Correct |
175 ms |
111696 KB |
Output is correct |
43 |
Correct |
157 ms |
111704 KB |
Output is correct |
44 |
Correct |
173 ms |
111760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
111668 KB |
Output is correct |
2 |
Correct |
198 ms |
111796 KB |
Output is correct |
3 |
Correct |
210 ms |
111740 KB |
Output is correct |
4 |
Correct |
143 ms |
111744 KB |
Output is correct |
5 |
Correct |
141 ms |
111784 KB |
Output is correct |
6 |
Correct |
154 ms |
111988 KB |
Output is correct |
7 |
Correct |
143 ms |
111696 KB |
Output is correct |
8 |
Correct |
154 ms |
111700 KB |
Output is correct |
9 |
Correct |
160 ms |
111696 KB |
Output is correct |
10 |
Correct |
153 ms |
111736 KB |
Output is correct |
11 |
Correct |
159 ms |
111700 KB |
Output is correct |
12 |
Correct |
153 ms |
111700 KB |
Output is correct |
13 |
Correct |
157 ms |
111832 KB |
Output is correct |
14 |
Correct |
152 ms |
111700 KB |
Output is correct |
15 |
Correct |
157 ms |
111784 KB |
Output is correct |
16 |
Correct |
153 ms |
111744 KB |
Output is correct |
17 |
Correct |
157 ms |
111696 KB |
Output is correct |
18 |
Correct |
195 ms |
111684 KB |
Output is correct |
19 |
Correct |
2053 ms |
117072 KB |
Output is correct |
20 |
Correct |
1310 ms |
118656 KB |
Output is correct |
21 |
Correct |
1047 ms |
120352 KB |
Output is correct |
22 |
Correct |
1103 ms |
120660 KB |
Output is correct |
23 |
Correct |
294 ms |
114388 KB |
Output is correct |
24 |
Correct |
296 ms |
114260 KB |
Output is correct |
25 |
Correct |
1087 ms |
120752 KB |
Output is correct |
26 |
Correct |
1249 ms |
120760 KB |
Output is correct |
27 |
Correct |
1723 ms |
120588 KB |
Output is correct |
28 |
Correct |
1650 ms |
120748 KB |
Output is correct |
29 |
Correct |
1472 ms |
120508 KB |
Output is correct |
30 |
Correct |
366 ms |
114332 KB |
Output is correct |
31 |
Correct |
1547 ms |
120916 KB |
Output is correct |
32 |
Correct |
1396 ms |
120404 KB |
Output is correct |
33 |
Correct |
319 ms |
114272 KB |
Output is correct |
34 |
Correct |
1506 ms |
120684 KB |
Output is correct |
35 |
Correct |
942 ms |
118356 KB |
Output is correct |
36 |
Correct |
305 ms |
114292 KB |
Output is correct |
37 |
Correct |
319 ms |
114776 KB |
Output is correct |
38 |
Correct |
1115 ms |
120588 KB |
Output is correct |
39 |
Correct |
354 ms |
120148 KB |
Output is correct |
40 |
Correct |
977 ms |
117968 KB |
Output is correct |
41 |
Correct |
1802 ms |
120944 KB |
Output is correct |
42 |
Correct |
143 ms |
120016 KB |
Output is correct |
43 |
Correct |
208 ms |
111796 KB |
Output is correct |
44 |
Correct |
211 ms |
111676 KB |
Output is correct |
45 |
Correct |
162 ms |
111648 KB |
Output is correct |
46 |
Correct |
141 ms |
111696 KB |
Output is correct |
47 |
Correct |
156 ms |
111828 KB |
Output is correct |
48 |
Correct |
167 ms |
112084 KB |
Output is correct |
49 |
Correct |
162 ms |
111696 KB |
Output is correct |
50 |
Correct |
150 ms |
111700 KB |
Output is correct |
51 |
Correct |
165 ms |
112044 KB |
Output is correct |
52 |
Correct |
150 ms |
111684 KB |
Output is correct |
53 |
Correct |
164 ms |
111696 KB |
Output is correct |
54 |
Correct |
142 ms |
111796 KB |
Output is correct |
55 |
Correct |
166 ms |
111696 KB |
Output is correct |
56 |
Correct |
167 ms |
111696 KB |
Output is correct |
57 |
Correct |
171 ms |
111700 KB |
Output is correct |
58 |
Correct |
153 ms |
111624 KB |
Output is correct |
59 |
Correct |
166 ms |
111696 KB |
Output is correct |
60 |
Correct |
177 ms |
111696 KB |
Output is correct |
61 |
Correct |
169 ms |
111696 KB |
Output is correct |
62 |
Correct |
172 ms |
111828 KB |
Output is correct |
63 |
Correct |
166 ms |
111696 KB |
Output is correct |
64 |
Correct |
176 ms |
111700 KB |
Output is correct |
65 |
Correct |
167 ms |
111700 KB |
Output is correct |
66 |
Correct |
175 ms |
111696 KB |
Output is correct |
67 |
Correct |
157 ms |
111704 KB |
Output is correct |
68 |
Correct |
173 ms |
111760 KB |
Output is correct |
69 |
Correct |
1780 ms |
120184 KB |
Output is correct |
70 |
Correct |
1374 ms |
120632 KB |
Output is correct |
71 |
Correct |
314 ms |
114272 KB |
Output is correct |
72 |
Correct |
308 ms |
114260 KB |
Output is correct |
73 |
Correct |
309 ms |
114272 KB |
Output is correct |
74 |
Correct |
1018 ms |
120200 KB |
Output is correct |
75 |
Correct |
313 ms |
114516 KB |
Output is correct |
76 |
Correct |
1113 ms |
120552 KB |
Output is correct |
77 |
Correct |
1139 ms |
120252 KB |
Output is correct |
78 |
Correct |
325 ms |
114320 KB |
Output is correct |
79 |
Correct |
315 ms |
114180 KB |
Output is correct |
80 |
Correct |
1020 ms |
118008 KB |
Output is correct |
81 |
Correct |
340 ms |
114284 KB |
Output is correct |
82 |
Correct |
1124 ms |
120700 KB |
Output is correct |
83 |
Correct |
1199 ms |
120592 KB |
Output is correct |
84 |
Correct |
348 ms |
114244 KB |
Output is correct |
85 |
Correct |
338 ms |
114344 KB |
Output is correct |
86 |
Correct |
1671 ms |
117804 KB |
Output is correct |
87 |
Correct |
1761 ms |
120704 KB |
Output is correct |
88 |
Correct |
449 ms |
114312 KB |
Output is correct |
89 |
Correct |
1402 ms |
120316 KB |
Output is correct |
90 |
Correct |
1503 ms |
120900 KB |
Output is correct |
91 |
Correct |
435 ms |
114260 KB |
Output is correct |
92 |
Correct |
1010 ms |
118092 KB |
Output is correct |
93 |
Correct |
354 ms |
114256 KB |
Output is correct |
94 |
Correct |
357 ms |
114368 KB |
Output is correct |
95 |
Correct |
343 ms |
114300 KB |
Output is correct |
96 |
Correct |
1146 ms |
120276 KB |
Output is correct |
97 |
Correct |
364 ms |
119996 KB |
Output is correct |
98 |
Correct |
1027 ms |
118048 KB |
Output is correct |
99 |
Correct |
1895 ms |
121004 KB |
Output is correct |
100 |
Correct |
157 ms |
120168 KB |
Output is correct |