#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
const int MOD = (1ll << 61) - 1;
const int b = 1e9 + 7;
map <char, int> ll = {
{'J', 0},
{'O', 1},
{'I', 2}
};
long long n;
const int MAXN = 200025;
int pw[MAXN];
int inv[MAXN];
int sub (int a, int b) {
if (!b) return pw[a];
return (pw[a] - pw[b - 1] + MOD) % MOD;
}
struct SegmentTree {
int tree[2 * MAXN], lazy[2 * MAXN];
void prop (int l, int r, int node) {
if (-1 == lazy[node]) return;
if (l == r) {
tree[node] = (lazy[node] * sub(l, l)) % MOD;
lazy[node] = -1;
return;
}
lazy[tl] = lazy[tr] = lazy[node];
tree[node] = (lazy[node] * sub(r, l)) % MOD;
lazy[node] = -1;
}
void update (int l, int r, int a, int b, int c, int node) {
prop(l, r, node);
if (l > b || r < a) return;
if (l >= a && r <= b) {
lazy[node] = c;
prop(l, r, node);
return;
}
update(l, mid, a, b, c, tl);
update(mid + 1, r, a, b, c, tr);
tree[node] = (tree[tl] + tree[tr]) % MOD;
}
int get (int l, int r, int a, int b, int node) {
prop(l, r, node);
if (l > b || r < a) return 0;
if (l >= a && r <= b) return tree[node];
return (get(l, mid, a, b, tl) + get(mid + 1, r, a, b, tr)) % MOD;
}
} cur;
int power (int a, int b) {
if (!b) return 1;
int u = power(a, b >> 1);
u = (u * u) % MOD;
if (b & 1) u = (u * a) % MOD;
return u;
}
int hashh (vector <int> a) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum = (sum + (a[i] * sub(i, i)) % MOD) % MOD;
}
return sum;
}
vector <int> merge (vector <int> a, vector <int> b) {
vector <int> c;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) {
c.push_back(a[i]);
} else {
set <int> u = {0, 1, 2};
u.erase(a[i]);
u.erase(b[i]);
int x = *(u.begin());
c.push_back(x);
}
}
return c;
}
set <int> ok;
void answer () {
if (ok.count(cur.get(0, n - 1, 0, n - 1, 1))) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0);
memset(cur.lazy, -1, sizeof(cur.lazy));
pw[0] = 1;
for (int i = 1; i < MAXN; i++) {
pw[i] = (b * pw[i - 1]) % MOD;
}
inv[MAXN - 1] = power(pw[MAXN - 1], MOD - 2);
for (int i = 1; i < MAXN; i++) {
pw[i] = (pw[i] + pw[i - 1]) % MOD;
}
for (int i = MAXN - 2; i >= 0; i--) {
inv[i] = (inv[i + 1] * b) % MOD;
}
cin >> n;
vector <int> a(n), b(n), c(n);
for (int i = 0; i < n; i++) {
char x;
cin >> x;
a[i] = ll[x];
}
for (int i = 0; i < n; i++) {
char x;
cin >> x;
b[i] = ll[x];
}
for (int i = 0; i < n; i++) {
char x;
cin >> x;
c[i] = ll[x];
}
ok.insert(hashh(a));
ok.insert(hashh(b));
ok.insert(hashh(c));
ok.insert(hashh(merge(a, b)));
ok.insert(hashh(merge(a, c)));
ok.insert(hashh(merge(b, c)));
ok.insert(hashh(merge(merge(a, b), c)));
ok.insert(hashh(merge(merge(a, c), b)));
ok.insert(hashh(merge(merge(b, c), a)));
long long q;
cin >> q;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
cur.update(0, n - 1, i, i, ll[s[i]], 1);
}
answer();
for (int i = 0; i < q; i++) {
long long l, r;
cin >> l >> r;
char x;
cin >> x;
int z = ll[x];
cur.update(0, n - 1, l - 1, r - 1, z, 1);
answer();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
16720 KB |
Output is correct |
2 |
Correct |
102 ms |
16924 KB |
Output is correct |
3 |
Correct |
104 ms |
16884 KB |
Output is correct |
4 |
Correct |
80 ms |
16940 KB |
Output is correct |
5 |
Correct |
79 ms |
16980 KB |
Output is correct |
6 |
Correct |
82 ms |
16816 KB |
Output is correct |
7 |
Correct |
79 ms |
16976 KB |
Output is correct |
8 |
Correct |
84 ms |
16980 KB |
Output is correct |
9 |
Correct |
88 ms |
16960 KB |
Output is correct |
10 |
Correct |
83 ms |
16976 KB |
Output is correct |
11 |
Correct |
85 ms |
17076 KB |
Output is correct |
12 |
Correct |
84 ms |
16976 KB |
Output is correct |
13 |
Correct |
88 ms |
16980 KB |
Output is correct |
14 |
Correct |
84 ms |
17104 KB |
Output is correct |
15 |
Correct |
86 ms |
17336 KB |
Output is correct |
16 |
Correct |
84 ms |
16980 KB |
Output is correct |
17 |
Correct |
87 ms |
16976 KB |
Output is correct |
18 |
Correct |
96 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
16720 KB |
Output is correct |
2 |
Correct |
102 ms |
16924 KB |
Output is correct |
3 |
Correct |
104 ms |
16884 KB |
Output is correct |
4 |
Correct |
80 ms |
16940 KB |
Output is correct |
5 |
Correct |
79 ms |
16980 KB |
Output is correct |
6 |
Correct |
82 ms |
16816 KB |
Output is correct |
7 |
Correct |
79 ms |
16976 KB |
Output is correct |
8 |
Correct |
84 ms |
16980 KB |
Output is correct |
9 |
Correct |
88 ms |
16960 KB |
Output is correct |
10 |
Correct |
83 ms |
16976 KB |
Output is correct |
11 |
Correct |
85 ms |
17076 KB |
Output is correct |
12 |
Correct |
84 ms |
16976 KB |
Output is correct |
13 |
Correct |
88 ms |
16980 KB |
Output is correct |
14 |
Correct |
84 ms |
17104 KB |
Output is correct |
15 |
Correct |
86 ms |
17336 KB |
Output is correct |
16 |
Correct |
84 ms |
16980 KB |
Output is correct |
17 |
Correct |
87 ms |
16976 KB |
Output is correct |
18 |
Correct |
96 ms |
16976 KB |
Output is correct |
19 |
Correct |
472 ms |
44748 KB |
Output is correct |
20 |
Correct |
469 ms |
45560 KB |
Output is correct |
21 |
Correct |
300 ms |
43444 KB |
Output is correct |
22 |
Correct |
310 ms |
42952 KB |
Output is correct |
23 |
Correct |
139 ms |
19168 KB |
Output is correct |
24 |
Correct |
147 ms |
19456 KB |
Output is correct |
25 |
Correct |
357 ms |
44860 KB |
Output is correct |
26 |
Correct |
388 ms |
45648 KB |
Output is correct |
27 |
Correct |
372 ms |
44904 KB |
Output is correct |
28 |
Correct |
387 ms |
45324 KB |
Output is correct |
29 |
Correct |
350 ms |
45196 KB |
Output is correct |
30 |
Correct |
168 ms |
19376 KB |
Output is correct |
31 |
Correct |
368 ms |
45564 KB |
Output is correct |
32 |
Correct |
374 ms |
43700 KB |
Output is correct |
33 |
Correct |
143 ms |
19212 KB |
Output is correct |
34 |
Correct |
415 ms |
45772 KB |
Output is correct |
35 |
Correct |
298 ms |
39556 KB |
Output is correct |
36 |
Correct |
141 ms |
19236 KB |
Output is correct |
37 |
Correct |
140 ms |
19204 KB |
Output is correct |
38 |
Correct |
409 ms |
46476 KB |
Output is correct |
39 |
Correct |
274 ms |
45160 KB |
Output is correct |
40 |
Correct |
269 ms |
35404 KB |
Output is correct |
41 |
Correct |
528 ms |
46632 KB |
Output is correct |
42 |
Correct |
171 ms |
45988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
16720 KB |
Output is correct |
2 |
Correct |
102 ms |
16924 KB |
Output is correct |
3 |
Correct |
104 ms |
16884 KB |
Output is correct |
4 |
Correct |
80 ms |
16940 KB |
Output is correct |
5 |
Correct |
79 ms |
16980 KB |
Output is correct |
6 |
Correct |
82 ms |
16816 KB |
Output is correct |
7 |
Correct |
79 ms |
16976 KB |
Output is correct |
8 |
Correct |
84 ms |
16980 KB |
Output is correct |
9 |
Correct |
88 ms |
16960 KB |
Output is correct |
10 |
Correct |
83 ms |
16976 KB |
Output is correct |
11 |
Correct |
85 ms |
17076 KB |
Output is correct |
12 |
Correct |
84 ms |
16976 KB |
Output is correct |
13 |
Correct |
88 ms |
16980 KB |
Output is correct |
14 |
Correct |
84 ms |
17104 KB |
Output is correct |
15 |
Correct |
86 ms |
17336 KB |
Output is correct |
16 |
Correct |
84 ms |
16980 KB |
Output is correct |
17 |
Correct |
87 ms |
16976 KB |
Output is correct |
18 |
Correct |
96 ms |
16976 KB |
Output is correct |
19 |
Correct |
103 ms |
17236 KB |
Output is correct |
20 |
Correct |
108 ms |
16916 KB |
Output is correct |
21 |
Correct |
104 ms |
17008 KB |
Output is correct |
22 |
Correct |
74 ms |
16724 KB |
Output is correct |
23 |
Correct |
90 ms |
17200 KB |
Output is correct |
24 |
Correct |
82 ms |
16880 KB |
Output is correct |
25 |
Correct |
86 ms |
16988 KB |
Output is correct |
26 |
Correct |
78 ms |
16976 KB |
Output is correct |
27 |
Correct |
96 ms |
17056 KB |
Output is correct |
28 |
Correct |
77 ms |
16724 KB |
Output is correct |
29 |
Correct |
86 ms |
17096 KB |
Output is correct |
30 |
Correct |
75 ms |
16708 KB |
Output is correct |
31 |
Correct |
86 ms |
16980 KB |
Output is correct |
32 |
Correct |
85 ms |
16908 KB |
Output is correct |
33 |
Correct |
87 ms |
16980 KB |
Output is correct |
34 |
Correct |
82 ms |
16968 KB |
Output is correct |
35 |
Correct |
100 ms |
16976 KB |
Output is correct |
36 |
Correct |
105 ms |
17072 KB |
Output is correct |
37 |
Correct |
103 ms |
16904 KB |
Output is correct |
38 |
Correct |
88 ms |
16976 KB |
Output is correct |
39 |
Correct |
86 ms |
16976 KB |
Output is correct |
40 |
Correct |
90 ms |
17008 KB |
Output is correct |
41 |
Correct |
87 ms |
16988 KB |
Output is correct |
42 |
Correct |
91 ms |
17020 KB |
Output is correct |
43 |
Correct |
83 ms |
16972 KB |
Output is correct |
44 |
Correct |
88 ms |
16964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
16720 KB |
Output is correct |
2 |
Correct |
102 ms |
16924 KB |
Output is correct |
3 |
Correct |
104 ms |
16884 KB |
Output is correct |
4 |
Correct |
80 ms |
16940 KB |
Output is correct |
5 |
Correct |
79 ms |
16980 KB |
Output is correct |
6 |
Correct |
82 ms |
16816 KB |
Output is correct |
7 |
Correct |
79 ms |
16976 KB |
Output is correct |
8 |
Correct |
84 ms |
16980 KB |
Output is correct |
9 |
Correct |
88 ms |
16960 KB |
Output is correct |
10 |
Correct |
83 ms |
16976 KB |
Output is correct |
11 |
Correct |
85 ms |
17076 KB |
Output is correct |
12 |
Correct |
84 ms |
16976 KB |
Output is correct |
13 |
Correct |
88 ms |
16980 KB |
Output is correct |
14 |
Correct |
84 ms |
17104 KB |
Output is correct |
15 |
Correct |
86 ms |
17336 KB |
Output is correct |
16 |
Correct |
84 ms |
16980 KB |
Output is correct |
17 |
Correct |
87 ms |
16976 KB |
Output is correct |
18 |
Correct |
96 ms |
16976 KB |
Output is correct |
19 |
Correct |
472 ms |
44748 KB |
Output is correct |
20 |
Correct |
469 ms |
45560 KB |
Output is correct |
21 |
Correct |
300 ms |
43444 KB |
Output is correct |
22 |
Correct |
310 ms |
42952 KB |
Output is correct |
23 |
Correct |
139 ms |
19168 KB |
Output is correct |
24 |
Correct |
147 ms |
19456 KB |
Output is correct |
25 |
Correct |
357 ms |
44860 KB |
Output is correct |
26 |
Correct |
388 ms |
45648 KB |
Output is correct |
27 |
Correct |
372 ms |
44904 KB |
Output is correct |
28 |
Correct |
387 ms |
45324 KB |
Output is correct |
29 |
Correct |
350 ms |
45196 KB |
Output is correct |
30 |
Correct |
168 ms |
19376 KB |
Output is correct |
31 |
Correct |
368 ms |
45564 KB |
Output is correct |
32 |
Correct |
374 ms |
43700 KB |
Output is correct |
33 |
Correct |
143 ms |
19212 KB |
Output is correct |
34 |
Correct |
415 ms |
45772 KB |
Output is correct |
35 |
Correct |
298 ms |
39556 KB |
Output is correct |
36 |
Correct |
141 ms |
19236 KB |
Output is correct |
37 |
Correct |
140 ms |
19204 KB |
Output is correct |
38 |
Correct |
409 ms |
46476 KB |
Output is correct |
39 |
Correct |
274 ms |
45160 KB |
Output is correct |
40 |
Correct |
269 ms |
35404 KB |
Output is correct |
41 |
Correct |
528 ms |
46632 KB |
Output is correct |
42 |
Correct |
171 ms |
45988 KB |
Output is correct |
43 |
Correct |
103 ms |
17236 KB |
Output is correct |
44 |
Correct |
108 ms |
16916 KB |
Output is correct |
45 |
Correct |
104 ms |
17008 KB |
Output is correct |
46 |
Correct |
74 ms |
16724 KB |
Output is correct |
47 |
Correct |
90 ms |
17200 KB |
Output is correct |
48 |
Correct |
82 ms |
16880 KB |
Output is correct |
49 |
Correct |
86 ms |
16988 KB |
Output is correct |
50 |
Correct |
78 ms |
16976 KB |
Output is correct |
51 |
Correct |
96 ms |
17056 KB |
Output is correct |
52 |
Correct |
77 ms |
16724 KB |
Output is correct |
53 |
Correct |
86 ms |
17096 KB |
Output is correct |
54 |
Correct |
75 ms |
16708 KB |
Output is correct |
55 |
Correct |
86 ms |
16980 KB |
Output is correct |
56 |
Correct |
85 ms |
16908 KB |
Output is correct |
57 |
Correct |
87 ms |
16980 KB |
Output is correct |
58 |
Correct |
82 ms |
16968 KB |
Output is correct |
59 |
Correct |
100 ms |
16976 KB |
Output is correct |
60 |
Correct |
105 ms |
17072 KB |
Output is correct |
61 |
Correct |
103 ms |
16904 KB |
Output is correct |
62 |
Correct |
88 ms |
16976 KB |
Output is correct |
63 |
Correct |
86 ms |
16976 KB |
Output is correct |
64 |
Correct |
90 ms |
17008 KB |
Output is correct |
65 |
Correct |
87 ms |
16988 KB |
Output is correct |
66 |
Correct |
91 ms |
17020 KB |
Output is correct |
67 |
Correct |
83 ms |
16972 KB |
Output is correct |
68 |
Correct |
88 ms |
16964 KB |
Output is correct |
69 |
Correct |
580 ms |
42296 KB |
Output is correct |
70 |
Correct |
597 ms |
46276 KB |
Output is correct |
71 |
Correct |
152 ms |
19448 KB |
Output is correct |
72 |
Correct |
147 ms |
19336 KB |
Output is correct |
73 |
Correct |
147 ms |
19400 KB |
Output is correct |
74 |
Correct |
371 ms |
41332 KB |
Output is correct |
75 |
Correct |
145 ms |
19180 KB |
Output is correct |
76 |
Correct |
437 ms |
45732 KB |
Output is correct |
77 |
Correct |
413 ms |
40452 KB |
Output is correct |
78 |
Correct |
149 ms |
19336 KB |
Output is correct |
79 |
Correct |
147 ms |
19184 KB |
Output is correct |
80 |
Correct |
373 ms |
37864 KB |
Output is correct |
81 |
Correct |
150 ms |
19216 KB |
Output is correct |
82 |
Correct |
469 ms |
46400 KB |
Output is correct |
83 |
Correct |
485 ms |
45568 KB |
Output is correct |
84 |
Correct |
149 ms |
19332 KB |
Output is correct |
85 |
Correct |
159 ms |
19196 KB |
Output is correct |
86 |
Correct |
427 ms |
41804 KB |
Output is correct |
87 |
Correct |
560 ms |
45512 KB |
Output is correct |
88 |
Correct |
171 ms |
19180 KB |
Output is correct |
89 |
Correct |
469 ms |
42696 KB |
Output is correct |
90 |
Correct |
534 ms |
44784 KB |
Output is correct |
91 |
Correct |
180 ms |
21000 KB |
Output is correct |
92 |
Correct |
416 ms |
38912 KB |
Output is correct |
93 |
Correct |
167 ms |
19220 KB |
Output is correct |
94 |
Correct |
161 ms |
19076 KB |
Output is correct |
95 |
Correct |
162 ms |
19340 KB |
Output is correct |
96 |
Correct |
486 ms |
44868 KB |
Output is correct |
97 |
Correct |
293 ms |
46848 KB |
Output is correct |
98 |
Correct |
416 ms |
35336 KB |
Output is correct |
99 |
Correct |
844 ms |
44880 KB |
Output is correct |
100 |
Correct |
318 ms |
44876 KB |
Output is correct |