#include <bits/stdc++.h>
using i64 = long long;
int pre[9][3][200005];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
auto in = [&]() {
std::string a;
std::cin >> a;
std::vector<int> b(n);
for (int i = 0; i < n; i++) {
b[i] = std::string("JOI").find(a[i]);
}
return b;
};
std::vector<int> a = in(), b = in(), c = in();
auto merge = [&](std::vector<int> a, std::vector<int> b) {
auto c = a;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
c[i] = 0 ^ 1 ^ 2 ^ a[i] ^ b[i];
}
}
return c;
};
std::vector<std::vector<int>> s{a, b, c, merge(a, b), merge(a, c), merge(b, c), merge(merge(a, c), b), merge(merge(a, b), c), merge(merge(b, c), a)};
int q;
std::cin >> q;
std::vector<int> t = in();
for (int k = 0; k < 9; k++) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
pre[k][i][j + 1] = pre[k][i][j] + (s[k][j] == i);
}
}
}
int bad[9] {};
for (int k = 0; k < 9; k++)
for (int i = 0; i < n; i++)
bad[k] += t[i] != s[k][i];
std::set<std::pair<int, int>> p{{-1, -1}, {n, -1}};
for (int i = 0; i < n; i++)
p.emplace(i, t[i]);
int ok = 0;
for (int k = 0; k < 9; k++) {
ok += bad[k] == 0;
}
if (ok) {
std::cout << "Yes\n";
} else {
std::cout << "No\n";
}
auto rem = [&](int l, int r, int c) {
for (int k = 0; k < 9; k++) {
bad[k] -= (pre[k][c][r] - pre[k][c][l] != r - l);
}
};
auto add = [&](int l, int r, int c) {
for (int k = 0; k < 9; k++) {
bad[k] += (pre[k][c][r] - pre[k][c][l] != r - l);
}
};
while (q--) {
int l, r;
char ch;
std::cin >> l >> r >> ch;
l--;
int x = std::string("JOI").find(ch);
// for (int i = l; i < r; i++) {
// t[i] = x;
// }
// if (s[0] == t) {
// std::cout << "Yes\n";
// } else {
// std::cout << "No\n";
// }
auto it = p.lower_bound({l, -1});
if (it->first > l) {
int L = std::prev(it)->first;
assert(L >= 0);
int R = it->first;
int c = std::prev(it)->second;
rem(L, R, c);
add(L, l, c);
add(l, R, c);
p.emplace(l, c);
}
it = p.lower_bound({r, -1});
if (it->first > r) {
int L = std::prev(it)->first;
assert(L >= 0);
int R = it->first;
int c = std::prev(it)->second;
rem(L, R, c);
add(L, r, c);
add(r, R, c);
p.emplace(r, c);
}
assert(p.lower_bound({l, -1})->first == l);
while (true) {
it = p.lower_bound({l, -1});
if (it->first < r) {
rem(it->first, std::next(it)->first, it->second);
p.erase(it);
} else {
break;
}
}
assert(p.lower_bound({l, -1})->first == r);
add(l, r, x);
p.emplace(l, x);
int ok = 0;
for (int k = 0; k < 9; k++) {
ok += bad[k] == 0;
}
if (ok) {
std::cout << "Yes\n";
} else {
std::cout << "No\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
1148 KB |
Output is correct |
2 |
Correct |
150 ms |
1108 KB |
Output is correct |
3 |
Correct |
109 ms |
1072 KB |
Output is correct |
4 |
Correct |
146 ms |
1088 KB |
Output is correct |
5 |
Correct |
145 ms |
1032 KB |
Output is correct |
6 |
Correct |
139 ms |
1152 KB |
Output is correct |
7 |
Correct |
140 ms |
1144 KB |
Output is correct |
8 |
Correct |
174 ms |
1068 KB |
Output is correct |
9 |
Correct |
147 ms |
1108 KB |
Output is correct |
10 |
Correct |
153 ms |
1080 KB |
Output is correct |
11 |
Correct |
151 ms |
1172 KB |
Output is correct |
12 |
Correct |
144 ms |
1144 KB |
Output is correct |
13 |
Correct |
151 ms |
1076 KB |
Output is correct |
14 |
Correct |
162 ms |
1320 KB |
Output is correct |
15 |
Correct |
146 ms |
1144 KB |
Output is correct |
16 |
Correct |
146 ms |
1040 KB |
Output is correct |
17 |
Correct |
155 ms |
1040 KB |
Output is correct |
18 |
Correct |
107 ms |
1176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
1148 KB |
Output is correct |
2 |
Correct |
150 ms |
1108 KB |
Output is correct |
3 |
Correct |
109 ms |
1072 KB |
Output is correct |
4 |
Correct |
146 ms |
1088 KB |
Output is correct |
5 |
Correct |
145 ms |
1032 KB |
Output is correct |
6 |
Correct |
139 ms |
1152 KB |
Output is correct |
7 |
Correct |
140 ms |
1144 KB |
Output is correct |
8 |
Correct |
174 ms |
1068 KB |
Output is correct |
9 |
Correct |
147 ms |
1108 KB |
Output is correct |
10 |
Correct |
153 ms |
1080 KB |
Output is correct |
11 |
Correct |
151 ms |
1172 KB |
Output is correct |
12 |
Correct |
144 ms |
1144 KB |
Output is correct |
13 |
Correct |
151 ms |
1076 KB |
Output is correct |
14 |
Correct |
162 ms |
1320 KB |
Output is correct |
15 |
Correct |
146 ms |
1144 KB |
Output is correct |
16 |
Correct |
146 ms |
1040 KB |
Output is correct |
17 |
Correct |
155 ms |
1040 KB |
Output is correct |
18 |
Correct |
107 ms |
1176 KB |
Output is correct |
19 |
Correct |
393 ms |
41760 KB |
Output is correct |
20 |
Correct |
264 ms |
42644 KB |
Output is correct |
21 |
Correct |
542 ms |
41476 KB |
Output is correct |
22 |
Correct |
475 ms |
37556 KB |
Output is correct |
23 |
Correct |
261 ms |
5940 KB |
Output is correct |
24 |
Correct |
248 ms |
5908 KB |
Output is correct |
25 |
Correct |
597 ms |
43852 KB |
Output is correct |
26 |
Correct |
516 ms |
43868 KB |
Output is correct |
27 |
Correct |
435 ms |
43876 KB |
Output is correct |
28 |
Correct |
447 ms |
43756 KB |
Output is correct |
29 |
Correct |
421 ms |
42936 KB |
Output is correct |
30 |
Correct |
229 ms |
5960 KB |
Output is correct |
31 |
Correct |
433 ms |
43940 KB |
Output is correct |
32 |
Correct |
443 ms |
40692 KB |
Output is correct |
33 |
Correct |
242 ms |
5888 KB |
Output is correct |
34 |
Correct |
472 ms |
43832 KB |
Output is correct |
35 |
Correct |
479 ms |
33456 KB |
Output is correct |
36 |
Correct |
246 ms |
5840 KB |
Output is correct |
37 |
Correct |
245 ms |
5876 KB |
Output is correct |
38 |
Correct |
235 ms |
43888 KB |
Output is correct |
39 |
Correct |
324 ms |
43788 KB |
Output is correct |
40 |
Correct |
474 ms |
29880 KB |
Output is correct |
41 |
Correct |
322 ms |
44044 KB |
Output is correct |
42 |
Correct |
155 ms |
44052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
1148 KB |
Output is correct |
2 |
Correct |
150 ms |
1108 KB |
Output is correct |
3 |
Correct |
109 ms |
1072 KB |
Output is correct |
4 |
Correct |
146 ms |
1088 KB |
Output is correct |
5 |
Correct |
145 ms |
1032 KB |
Output is correct |
6 |
Correct |
139 ms |
1152 KB |
Output is correct |
7 |
Correct |
140 ms |
1144 KB |
Output is correct |
8 |
Correct |
174 ms |
1068 KB |
Output is correct |
9 |
Correct |
147 ms |
1108 KB |
Output is correct |
10 |
Correct |
153 ms |
1080 KB |
Output is correct |
11 |
Correct |
151 ms |
1172 KB |
Output is correct |
12 |
Correct |
144 ms |
1144 KB |
Output is correct |
13 |
Correct |
151 ms |
1076 KB |
Output is correct |
14 |
Correct |
162 ms |
1320 KB |
Output is correct |
15 |
Correct |
146 ms |
1144 KB |
Output is correct |
16 |
Correct |
146 ms |
1040 KB |
Output is correct |
17 |
Correct |
155 ms |
1040 KB |
Output is correct |
18 |
Correct |
107 ms |
1176 KB |
Output is correct |
19 |
Correct |
145 ms |
1048 KB |
Output is correct |
20 |
Correct |
107 ms |
1092 KB |
Output is correct |
21 |
Correct |
149 ms |
1128 KB |
Output is correct |
22 |
Correct |
126 ms |
2304 KB |
Output is correct |
23 |
Correct |
150 ms |
2624 KB |
Output is correct |
24 |
Correct |
139 ms |
2428 KB |
Output is correct |
25 |
Correct |
143 ms |
2568 KB |
Output is correct |
26 |
Correct |
139 ms |
2568 KB |
Output is correct |
27 |
Correct |
143 ms |
2552 KB |
Output is correct |
28 |
Correct |
129 ms |
2336 KB |
Output is correct |
29 |
Correct |
145 ms |
2608 KB |
Output is correct |
30 |
Correct |
131 ms |
2428 KB |
Output is correct |
31 |
Correct |
142 ms |
2536 KB |
Output is correct |
32 |
Correct |
141 ms |
2556 KB |
Output is correct |
33 |
Correct |
163 ms |
2708 KB |
Output is correct |
34 |
Correct |
130 ms |
2376 KB |
Output is correct |
35 |
Correct |
143 ms |
2540 KB |
Output is correct |
36 |
Correct |
148 ms |
2572 KB |
Output is correct |
37 |
Correct |
144 ms |
2568 KB |
Output is correct |
38 |
Correct |
150 ms |
2536 KB |
Output is correct |
39 |
Correct |
144 ms |
2504 KB |
Output is correct |
40 |
Correct |
151 ms |
2660 KB |
Output is correct |
41 |
Correct |
147 ms |
2592 KB |
Output is correct |
42 |
Correct |
149 ms |
2608 KB |
Output is correct |
43 |
Correct |
136 ms |
2500 KB |
Output is correct |
44 |
Correct |
147 ms |
2620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
1148 KB |
Output is correct |
2 |
Correct |
150 ms |
1108 KB |
Output is correct |
3 |
Correct |
109 ms |
1072 KB |
Output is correct |
4 |
Correct |
146 ms |
1088 KB |
Output is correct |
5 |
Correct |
145 ms |
1032 KB |
Output is correct |
6 |
Correct |
139 ms |
1152 KB |
Output is correct |
7 |
Correct |
140 ms |
1144 KB |
Output is correct |
8 |
Correct |
174 ms |
1068 KB |
Output is correct |
9 |
Correct |
147 ms |
1108 KB |
Output is correct |
10 |
Correct |
153 ms |
1080 KB |
Output is correct |
11 |
Correct |
151 ms |
1172 KB |
Output is correct |
12 |
Correct |
144 ms |
1144 KB |
Output is correct |
13 |
Correct |
151 ms |
1076 KB |
Output is correct |
14 |
Correct |
162 ms |
1320 KB |
Output is correct |
15 |
Correct |
146 ms |
1144 KB |
Output is correct |
16 |
Correct |
146 ms |
1040 KB |
Output is correct |
17 |
Correct |
155 ms |
1040 KB |
Output is correct |
18 |
Correct |
107 ms |
1176 KB |
Output is correct |
19 |
Correct |
393 ms |
41760 KB |
Output is correct |
20 |
Correct |
264 ms |
42644 KB |
Output is correct |
21 |
Correct |
542 ms |
41476 KB |
Output is correct |
22 |
Correct |
475 ms |
37556 KB |
Output is correct |
23 |
Correct |
261 ms |
5940 KB |
Output is correct |
24 |
Correct |
248 ms |
5908 KB |
Output is correct |
25 |
Correct |
597 ms |
43852 KB |
Output is correct |
26 |
Correct |
516 ms |
43868 KB |
Output is correct |
27 |
Correct |
435 ms |
43876 KB |
Output is correct |
28 |
Correct |
447 ms |
43756 KB |
Output is correct |
29 |
Correct |
421 ms |
42936 KB |
Output is correct |
30 |
Correct |
229 ms |
5960 KB |
Output is correct |
31 |
Correct |
433 ms |
43940 KB |
Output is correct |
32 |
Correct |
443 ms |
40692 KB |
Output is correct |
33 |
Correct |
242 ms |
5888 KB |
Output is correct |
34 |
Correct |
472 ms |
43832 KB |
Output is correct |
35 |
Correct |
479 ms |
33456 KB |
Output is correct |
36 |
Correct |
246 ms |
5840 KB |
Output is correct |
37 |
Correct |
245 ms |
5876 KB |
Output is correct |
38 |
Correct |
235 ms |
43888 KB |
Output is correct |
39 |
Correct |
324 ms |
43788 KB |
Output is correct |
40 |
Correct |
474 ms |
29880 KB |
Output is correct |
41 |
Correct |
322 ms |
44044 KB |
Output is correct |
42 |
Correct |
155 ms |
44052 KB |
Output is correct |
43 |
Correct |
145 ms |
1048 KB |
Output is correct |
44 |
Correct |
107 ms |
1092 KB |
Output is correct |
45 |
Correct |
149 ms |
1128 KB |
Output is correct |
46 |
Correct |
126 ms |
2304 KB |
Output is correct |
47 |
Correct |
150 ms |
2624 KB |
Output is correct |
48 |
Correct |
139 ms |
2428 KB |
Output is correct |
49 |
Correct |
143 ms |
2568 KB |
Output is correct |
50 |
Correct |
139 ms |
2568 KB |
Output is correct |
51 |
Correct |
143 ms |
2552 KB |
Output is correct |
52 |
Correct |
129 ms |
2336 KB |
Output is correct |
53 |
Correct |
145 ms |
2608 KB |
Output is correct |
54 |
Correct |
131 ms |
2428 KB |
Output is correct |
55 |
Correct |
142 ms |
2536 KB |
Output is correct |
56 |
Correct |
141 ms |
2556 KB |
Output is correct |
57 |
Correct |
163 ms |
2708 KB |
Output is correct |
58 |
Correct |
130 ms |
2376 KB |
Output is correct |
59 |
Correct |
143 ms |
2540 KB |
Output is correct |
60 |
Correct |
148 ms |
2572 KB |
Output is correct |
61 |
Correct |
144 ms |
2568 KB |
Output is correct |
62 |
Correct |
150 ms |
2536 KB |
Output is correct |
63 |
Correct |
144 ms |
2504 KB |
Output is correct |
64 |
Correct |
151 ms |
2660 KB |
Output is correct |
65 |
Correct |
147 ms |
2592 KB |
Output is correct |
66 |
Correct |
149 ms |
2608 KB |
Output is correct |
67 |
Correct |
136 ms |
2500 KB |
Output is correct |
68 |
Correct |
147 ms |
2620 KB |
Output is correct |
69 |
Correct |
330 ms |
37284 KB |
Output is correct |
70 |
Correct |
271 ms |
43756 KB |
Output is correct |
71 |
Correct |
247 ms |
5832 KB |
Output is correct |
72 |
Correct |
246 ms |
5956 KB |
Output is correct |
73 |
Correct |
259 ms |
5944 KB |
Output is correct |
74 |
Correct |
465 ms |
37092 KB |
Output is correct |
75 |
Correct |
252 ms |
6084 KB |
Output is correct |
76 |
Correct |
534 ms |
43752 KB |
Output is correct |
77 |
Correct |
439 ms |
37328 KB |
Output is correct |
78 |
Correct |
248 ms |
5956 KB |
Output is correct |
79 |
Correct |
253 ms |
5900 KB |
Output is correct |
80 |
Correct |
427 ms |
32172 KB |
Output is correct |
81 |
Correct |
263 ms |
5808 KB |
Output is correct |
82 |
Correct |
546 ms |
43848 KB |
Output is correct |
83 |
Correct |
461 ms |
41572 KB |
Output is correct |
84 |
Correct |
243 ms |
5832 KB |
Output is correct |
85 |
Correct |
250 ms |
5800 KB |
Output is correct |
86 |
Correct |
362 ms |
34256 KB |
Output is correct |
87 |
Correct |
439 ms |
43812 KB |
Output is correct |
88 |
Correct |
230 ms |
5916 KB |
Output is correct |
89 |
Correct |
413 ms |
39020 KB |
Output is correct |
90 |
Correct |
450 ms |
43876 KB |
Output is correct |
91 |
Correct |
230 ms |
5876 KB |
Output is correct |
92 |
Correct |
464 ms |
33764 KB |
Output is correct |
93 |
Correct |
246 ms |
5828 KB |
Output is correct |
94 |
Correct |
256 ms |
5872 KB |
Output is correct |
95 |
Correct |
247 ms |
5840 KB |
Output is correct |
96 |
Correct |
230 ms |
43900 KB |
Output is correct |
97 |
Correct |
314 ms |
43876 KB |
Output is correct |
98 |
Correct |
466 ms |
29912 KB |
Output is correct |
99 |
Correct |
306 ms |
44072 KB |
Output is correct |
100 |
Correct |
165 ms |
44060 KB |
Output is correct |