#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/// Delete all asserts for extra Boost
class Node {
public:
bool stequal = false;
bool jequal = false;
bool oequal = false;
bool iequal = false;
};
Node operator + (Node a, Node b) {
a.stequal &= b.stequal;
a.jequal &= b.jequal;
a.oequal &= b.oequal;
a.iequal &= b.iequal;
return a;
}
class IsEqual {
private:
string s;
string t;
int n;
vector<Node> tree;
vector<char> lazy;
void build(int v, int tl, int tr) {
if (tl == tr) {
tree[v].stequal = (s[tl] == t[tl]);
tree[v].jequal = (s[tl] == 'J');
tree[v].oequal = (s[tl] == 'O');
tree[v].iequal = (s[tl] == 'I');
} else {
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
tree[v] = tree[2 * v] + tree[2 * v + 1];
}
}
void modify(int v, int tl, int tr, int l, int r, char ch) {
if (lazy[v] != 'X') { /// push
assert(lazy[v] == 'J' || lazy[v] == 'O' || lazy[v] == 'I');
if (lazy[v] == 'J') {
tree[v].stequal = tree[v].jequal;
} else {
if (lazy[v] == 'O') {
tree[v].stequal = tree[v].oequal;
} else {
tree[v].stequal = tree[v].iequal;
}
}
if (tl < tr) {
lazy[2 * v] = lazy[2 * v + 1] = lazy[v];
}
lazy[v] = 'X';
}
if (tr < l || r < tl) {
return;
}
if (l <= tl && tr <= r) {
lazy[v] = ch;
assert(lazy[v] == 'J' || lazy[v] == 'O' || lazy[v] == 'I');
if (lazy[v] == 'J') {
tree[v].stequal = tree[v].jequal;
} else {
if (lazy[v] == 'O') {
tree[v].stequal = tree[v].oequal;
} else {
tree[v].stequal = tree[v].iequal;
}
}
if (tl < tr) {
lazy[2 * v] = lazy[2 * v + 1] = lazy[v];
}
lazy[v] = 'X';
} else {
int tm = (tl + tr) / 2;
modify(2 * v, tl, tm, l, r, ch);
modify(2 * v + 1, tm + 1, tr, l, r, ch);
tree[v] = tree[2 * v] + tree[2 * v + 1];
}
}
public:
IsEqual(string s, string t) : s(s), t(t), n((int) s.size()), tree(4 * ((int) s.size() + 7)), lazy(4 * ((int) s.size()), 'X') {
assert((int) s.size() == (int) t.size());
build(1, 0, n - 1);
}
void modify(int l, int r, char ch) {
l--;
r--;
assert(0 <= l && l <= r && r < n);
modify(1, 0, n - 1, l, r, ch);
}
bool isEqual() {
return tree[1].stequal;
}
};
string operator + (string s, string t) {
assert((int) s.size() == (int) t.size());
for (int i = 0; i < (int) s.size(); i++) {
if (s[i] != t[i]) {
int x = 'J' + 'O' + 'I' - s[i] - t[i];
s[i] = x;
}
}
return s;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
/// freopen ("TonyStark", "r", stdin);
int n, q;
string a, b, c, t;
vector<IsEqual> all;
cin >> n >> a >> b >> c >> q >> t;
all.push_back({a, t});
all.push_back({b, t});
all.push_back({c, t});
all.push_back({a + b, t});
all.push_back({b + c, t});
all.push_back({c + a, t});
all.push_back({a + (b + c), t});
all.push_back({b + (c + a), t});
all.push_back({c + (a + b), t});
function <string()> solve = [&] () {
bool ok = false;
for (auto &x : all) {
ok |= x.isEqual();
}
if (ok) {
return "Yes";
} else {
return "No";
}
};
cout << solve() << "\n";
while (q--) {
int l, r;
string ch;
cin >> l >> r >> ch;
for (auto& x : all) {
x.modify(l, r, ch[0]);
}
cout << solve() << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
2192 KB |
Output is correct |
2 |
Correct |
413 ms |
2368 KB |
Output is correct |
3 |
Correct |
476 ms |
2400 KB |
Output is correct |
4 |
Correct |
298 ms |
2372 KB |
Output is correct |
5 |
Correct |
291 ms |
2244 KB |
Output is correct |
6 |
Correct |
319 ms |
2416 KB |
Output is correct |
7 |
Correct |
317 ms |
2384 KB |
Output is correct |
8 |
Correct |
328 ms |
2396 KB |
Output is correct |
9 |
Correct |
335 ms |
2412 KB |
Output is correct |
10 |
Correct |
346 ms |
2360 KB |
Output is correct |
11 |
Correct |
325 ms |
2376 KB |
Output is correct |
12 |
Correct |
331 ms |
2464 KB |
Output is correct |
13 |
Correct |
337 ms |
2408 KB |
Output is correct |
14 |
Correct |
317 ms |
2340 KB |
Output is correct |
15 |
Correct |
332 ms |
2552 KB |
Output is correct |
16 |
Correct |
323 ms |
2424 KB |
Output is correct |
17 |
Correct |
337 ms |
2428 KB |
Output is correct |
18 |
Correct |
430 ms |
2532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
2192 KB |
Output is correct |
2 |
Correct |
413 ms |
2368 KB |
Output is correct |
3 |
Correct |
476 ms |
2400 KB |
Output is correct |
4 |
Correct |
298 ms |
2372 KB |
Output is correct |
5 |
Correct |
291 ms |
2244 KB |
Output is correct |
6 |
Correct |
319 ms |
2416 KB |
Output is correct |
7 |
Correct |
317 ms |
2384 KB |
Output is correct |
8 |
Correct |
328 ms |
2396 KB |
Output is correct |
9 |
Correct |
335 ms |
2412 KB |
Output is correct |
10 |
Correct |
346 ms |
2360 KB |
Output is correct |
11 |
Correct |
325 ms |
2376 KB |
Output is correct |
12 |
Correct |
331 ms |
2464 KB |
Output is correct |
13 |
Correct |
337 ms |
2408 KB |
Output is correct |
14 |
Correct |
317 ms |
2340 KB |
Output is correct |
15 |
Correct |
332 ms |
2552 KB |
Output is correct |
16 |
Correct |
323 ms |
2424 KB |
Output is correct |
17 |
Correct |
337 ms |
2428 KB |
Output is correct |
18 |
Correct |
430 ms |
2532 KB |
Output is correct |
19 |
Correct |
2074 ms |
45124 KB |
Output is correct |
20 |
Correct |
1931 ms |
44980 KB |
Output is correct |
21 |
Correct |
1096 ms |
42320 KB |
Output is correct |
22 |
Correct |
1121 ms |
38436 KB |
Output is correct |
23 |
Correct |
636 ms |
5388 KB |
Output is correct |
24 |
Correct |
610 ms |
5356 KB |
Output is correct |
25 |
Correct |
1147 ms |
44940 KB |
Output is correct |
26 |
Correct |
1237 ms |
44912 KB |
Output is correct |
27 |
Correct |
1417 ms |
45180 KB |
Output is correct |
28 |
Correct |
1460 ms |
45020 KB |
Output is correct |
29 |
Correct |
1360 ms |
43860 KB |
Output is correct |
30 |
Correct |
715 ms |
5444 KB |
Output is correct |
31 |
Correct |
1465 ms |
44932 KB |
Output is correct |
32 |
Correct |
1331 ms |
41172 KB |
Output is correct |
33 |
Correct |
649 ms |
5308 KB |
Output is correct |
34 |
Correct |
1423 ms |
45040 KB |
Output is correct |
35 |
Correct |
1020 ms |
34284 KB |
Output is correct |
36 |
Correct |
620 ms |
5444 KB |
Output is correct |
37 |
Correct |
613 ms |
5352 KB |
Output is correct |
38 |
Correct |
1543 ms |
44756 KB |
Output is correct |
39 |
Correct |
733 ms |
45116 KB |
Output is correct |
40 |
Correct |
1052 ms |
30788 KB |
Output is correct |
41 |
Correct |
2260 ms |
45328 KB |
Output is correct |
42 |
Correct |
129 ms |
44300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
2192 KB |
Output is correct |
2 |
Correct |
413 ms |
2368 KB |
Output is correct |
3 |
Correct |
476 ms |
2400 KB |
Output is correct |
4 |
Correct |
298 ms |
2372 KB |
Output is correct |
5 |
Correct |
291 ms |
2244 KB |
Output is correct |
6 |
Correct |
319 ms |
2416 KB |
Output is correct |
7 |
Correct |
317 ms |
2384 KB |
Output is correct |
8 |
Correct |
328 ms |
2396 KB |
Output is correct |
9 |
Correct |
335 ms |
2412 KB |
Output is correct |
10 |
Correct |
346 ms |
2360 KB |
Output is correct |
11 |
Correct |
325 ms |
2376 KB |
Output is correct |
12 |
Correct |
331 ms |
2464 KB |
Output is correct |
13 |
Correct |
337 ms |
2408 KB |
Output is correct |
14 |
Correct |
317 ms |
2340 KB |
Output is correct |
15 |
Correct |
332 ms |
2552 KB |
Output is correct |
16 |
Correct |
323 ms |
2424 KB |
Output is correct |
17 |
Correct |
337 ms |
2428 KB |
Output is correct |
18 |
Correct |
430 ms |
2532 KB |
Output is correct |
19 |
Correct |
393 ms |
2256 KB |
Output is correct |
20 |
Correct |
479 ms |
2260 KB |
Output is correct |
21 |
Correct |
320 ms |
2372 KB |
Output is correct |
22 |
Correct |
273 ms |
2136 KB |
Output is correct |
23 |
Correct |
320 ms |
2484 KB |
Output is correct |
24 |
Correct |
314 ms |
2368 KB |
Output is correct |
25 |
Correct |
353 ms |
2400 KB |
Output is correct |
26 |
Correct |
296 ms |
2324 KB |
Output is correct |
27 |
Correct |
323 ms |
2412 KB |
Output is correct |
28 |
Correct |
284 ms |
2208 KB |
Output is correct |
29 |
Correct |
335 ms |
2392 KB |
Output is correct |
30 |
Correct |
284 ms |
2268 KB |
Output is correct |
31 |
Correct |
327 ms |
2432 KB |
Output is correct |
32 |
Correct |
317 ms |
2328 KB |
Output is correct |
33 |
Correct |
323 ms |
2444 KB |
Output is correct |
34 |
Correct |
286 ms |
2180 KB |
Output is correct |
35 |
Correct |
314 ms |
2420 KB |
Output is correct |
36 |
Correct |
327 ms |
2428 KB |
Output is correct |
37 |
Correct |
327 ms |
2372 KB |
Output is correct |
38 |
Correct |
320 ms |
2404 KB |
Output is correct |
39 |
Correct |
318 ms |
2648 KB |
Output is correct |
40 |
Correct |
325 ms |
2472 KB |
Output is correct |
41 |
Correct |
319 ms |
2736 KB |
Output is correct |
42 |
Correct |
329 ms |
2516 KB |
Output is correct |
43 |
Correct |
304 ms |
2304 KB |
Output is correct |
44 |
Correct |
324 ms |
2340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
2192 KB |
Output is correct |
2 |
Correct |
413 ms |
2368 KB |
Output is correct |
3 |
Correct |
476 ms |
2400 KB |
Output is correct |
4 |
Correct |
298 ms |
2372 KB |
Output is correct |
5 |
Correct |
291 ms |
2244 KB |
Output is correct |
6 |
Correct |
319 ms |
2416 KB |
Output is correct |
7 |
Correct |
317 ms |
2384 KB |
Output is correct |
8 |
Correct |
328 ms |
2396 KB |
Output is correct |
9 |
Correct |
335 ms |
2412 KB |
Output is correct |
10 |
Correct |
346 ms |
2360 KB |
Output is correct |
11 |
Correct |
325 ms |
2376 KB |
Output is correct |
12 |
Correct |
331 ms |
2464 KB |
Output is correct |
13 |
Correct |
337 ms |
2408 KB |
Output is correct |
14 |
Correct |
317 ms |
2340 KB |
Output is correct |
15 |
Correct |
332 ms |
2552 KB |
Output is correct |
16 |
Correct |
323 ms |
2424 KB |
Output is correct |
17 |
Correct |
337 ms |
2428 KB |
Output is correct |
18 |
Correct |
430 ms |
2532 KB |
Output is correct |
19 |
Correct |
2074 ms |
45124 KB |
Output is correct |
20 |
Correct |
1931 ms |
44980 KB |
Output is correct |
21 |
Correct |
1096 ms |
42320 KB |
Output is correct |
22 |
Correct |
1121 ms |
38436 KB |
Output is correct |
23 |
Correct |
636 ms |
5388 KB |
Output is correct |
24 |
Correct |
610 ms |
5356 KB |
Output is correct |
25 |
Correct |
1147 ms |
44940 KB |
Output is correct |
26 |
Correct |
1237 ms |
44912 KB |
Output is correct |
27 |
Correct |
1417 ms |
45180 KB |
Output is correct |
28 |
Correct |
1460 ms |
45020 KB |
Output is correct |
29 |
Correct |
1360 ms |
43860 KB |
Output is correct |
30 |
Correct |
715 ms |
5444 KB |
Output is correct |
31 |
Correct |
1465 ms |
44932 KB |
Output is correct |
32 |
Correct |
1331 ms |
41172 KB |
Output is correct |
33 |
Correct |
649 ms |
5308 KB |
Output is correct |
34 |
Correct |
1423 ms |
45040 KB |
Output is correct |
35 |
Correct |
1020 ms |
34284 KB |
Output is correct |
36 |
Correct |
620 ms |
5444 KB |
Output is correct |
37 |
Correct |
613 ms |
5352 KB |
Output is correct |
38 |
Correct |
1543 ms |
44756 KB |
Output is correct |
39 |
Correct |
733 ms |
45116 KB |
Output is correct |
40 |
Correct |
1052 ms |
30788 KB |
Output is correct |
41 |
Correct |
2260 ms |
45328 KB |
Output is correct |
42 |
Correct |
129 ms |
44300 KB |
Output is correct |
43 |
Correct |
393 ms |
2256 KB |
Output is correct |
44 |
Correct |
479 ms |
2260 KB |
Output is correct |
45 |
Correct |
320 ms |
2372 KB |
Output is correct |
46 |
Correct |
273 ms |
2136 KB |
Output is correct |
47 |
Correct |
320 ms |
2484 KB |
Output is correct |
48 |
Correct |
314 ms |
2368 KB |
Output is correct |
49 |
Correct |
353 ms |
2400 KB |
Output is correct |
50 |
Correct |
296 ms |
2324 KB |
Output is correct |
51 |
Correct |
323 ms |
2412 KB |
Output is correct |
52 |
Correct |
284 ms |
2208 KB |
Output is correct |
53 |
Correct |
335 ms |
2392 KB |
Output is correct |
54 |
Correct |
284 ms |
2268 KB |
Output is correct |
55 |
Correct |
327 ms |
2432 KB |
Output is correct |
56 |
Correct |
317 ms |
2328 KB |
Output is correct |
57 |
Correct |
323 ms |
2444 KB |
Output is correct |
58 |
Correct |
286 ms |
2180 KB |
Output is correct |
59 |
Correct |
314 ms |
2420 KB |
Output is correct |
60 |
Correct |
327 ms |
2428 KB |
Output is correct |
61 |
Correct |
327 ms |
2372 KB |
Output is correct |
62 |
Correct |
320 ms |
2404 KB |
Output is correct |
63 |
Correct |
318 ms |
2648 KB |
Output is correct |
64 |
Correct |
325 ms |
2472 KB |
Output is correct |
65 |
Correct |
319 ms |
2736 KB |
Output is correct |
66 |
Correct |
329 ms |
2516 KB |
Output is correct |
67 |
Correct |
304 ms |
2304 KB |
Output is correct |
68 |
Correct |
324 ms |
2340 KB |
Output is correct |
69 |
Correct |
1687 ms |
38032 KB |
Output is correct |
70 |
Correct |
1843 ms |
45064 KB |
Output is correct |
71 |
Correct |
623 ms |
5448 KB |
Output is correct |
72 |
Correct |
630 ms |
5460 KB |
Output is correct |
73 |
Correct |
623 ms |
5440 KB |
Output is correct |
74 |
Correct |
1062 ms |
37904 KB |
Output is correct |
75 |
Correct |
628 ms |
5192 KB |
Output is correct |
76 |
Correct |
1268 ms |
44984 KB |
Output is correct |
77 |
Correct |
1175 ms |
38244 KB |
Output is correct |
78 |
Correct |
636 ms |
5504 KB |
Output is correct |
79 |
Correct |
617 ms |
5320 KB |
Output is correct |
80 |
Correct |
1127 ms |
32700 KB |
Output is correct |
81 |
Correct |
628 ms |
5216 KB |
Output is correct |
82 |
Correct |
1197 ms |
44956 KB |
Output is correct |
83 |
Correct |
1182 ms |
42320 KB |
Output is correct |
84 |
Correct |
638 ms |
5320 KB |
Output is correct |
85 |
Correct |
656 ms |
5344 KB |
Output is correct |
86 |
Correct |
1412 ms |
34804 KB |
Output is correct |
87 |
Correct |
1459 ms |
44996 KB |
Output is correct |
88 |
Correct |
758 ms |
5584 KB |
Output is correct |
89 |
Correct |
1281 ms |
39928 KB |
Output is correct |
90 |
Correct |
1418 ms |
44944 KB |
Output is correct |
91 |
Correct |
746 ms |
5356 KB |
Output is correct |
92 |
Correct |
1074 ms |
34484 KB |
Output is correct |
93 |
Correct |
625 ms |
5260 KB |
Output is correct |
94 |
Correct |
598 ms |
5316 KB |
Output is correct |
95 |
Correct |
624 ms |
5316 KB |
Output is correct |
96 |
Correct |
1547 ms |
44724 KB |
Output is correct |
97 |
Correct |
715 ms |
45020 KB |
Output is correct |
98 |
Correct |
1088 ms |
30864 KB |
Output is correct |
99 |
Correct |
2217 ms |
45196 KB |
Output is correct |
100 |
Correct |
134 ms |
44428 KB |
Output is correct |