#include <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
using H = pair<int, int>;
H add(H a, H b) {
a.first += b.first;
if (a.first >= MOD1)
a.first -= MOD1;
a.second += b.second;
if (a.second >= MOD2)
a.second -= MOD2;
return a;
}
H sub(H a, H b) {
a.first -= b.first;
a.second -= b.second;
if (a.first < 0)
a.first += MOD1;
if (a.second < 0)
a.second += MOD2;
return a;
}
H mult(H a, H b) {
return pair(a.first * b.first % MOD1, a.second * b.second % MOD2);
}
const int MAXN = 1e6;
const int BASE = 315;
H pows[MAXN];
int iDeb[MAXN], iFin[MAXN];
H sumPows[MAXN], rangeHash[MAXN];
int lazy[MAXN];
void pull(int node) {
sumPows[node] = add(sumPows[2 * node], sumPows[2 * node + 1]);
rangeHash[node] = add(rangeHash[2 * node], rangeHash[2 * node + 1]);
}
void build(int node, int l, int r) {
iDeb[node] = l, iFin[node] = r;
lazy[node] = -1;
if (l == r) {
sumPows[node] = pows[l];
return;
}
int m = (l + r) / 2;
build(2 * node, l, m);
build(2 * node + 1, m + 1, r);
pull(node);
}
void push(int node) {
if (lazy[node] == -1)
return;
int x = lazy[node];
lazy[node] = -1;
rangeHash[node] = mult(pair(x, x), sumPows[node]);
if (iDeb[node] < iFin[node])
lazy[2 * node] = lazy[2 * node + 1] = x;
}
void rangeSet(int node, int l, int r, int x) {
push(node);
if (l > iFin[node] or r < iDeb[node])
return;
if (l <= iDeb[node] and iFin[node] <= r) {
lazy[node] = x;
push(node);
return;
}
rangeSet(2 * node, l, r, x);
rangeSet(2 * node + 1, l, r, x);
pull(node);
}
int charToint(char c) {
if (c == 'J')
return 0;
if (c == 'O')
return 1;
return 2;
}
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
pows[0] = pair(1, 1);
for (int i = 1; i < MAXN; ++i)
pows[i] = mult(pows[i - 1], pair(BASE, BASE));
int N;
cin >> N;
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
build(1, 0, N - 1);
set<H> goodHash;
for (int n1 = 0; n1 < 3; ++n1)
for (int n2 = 0; n2 < 3; ++n2)
for (int n3 = 0; n3 < 3; ++n3)
if ((n1 + n2 + n3) % 3 == 1) {
H h(0, 0);
for (int i = 0; i < N; ++i) {
int x = (n1 * charToint(s1[i]) + n2 * charToint(s2[i]) +
n3 * charToint(s3[i])) %
3;
h = add(h, mult(pair(x, x), pows[i]));
}
goodHash.insert(h);
}
int Q;
cin >> Q;
string T0;
cin >> T0;
for (int i = 0; i < N; ++i)
rangeSet(1, i, i, charToint(T0[i]));
cout << (goodHash.count(rangeHash[1]) ? "Yes" : "No") << '\n';
for (int i = 0; i < Q; ++i) {
int L, R;
char c;
cin >> L >> R >> c;
rangeSet(1, L - 1, R - 1, charToint(c));
cout << (goodHash.count(rangeHash[1]) ? "Yes" : "No") << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
16912 KB |
Output is correct |
2 |
Correct |
91 ms |
16984 KB |
Output is correct |
3 |
Correct |
88 ms |
16992 KB |
Output is correct |
4 |
Correct |
77 ms |
16980 KB |
Output is correct |
5 |
Correct |
78 ms |
16856 KB |
Output is correct |
6 |
Correct |
80 ms |
16912 KB |
Output is correct |
7 |
Correct |
81 ms |
16884 KB |
Output is correct |
8 |
Correct |
81 ms |
16972 KB |
Output is correct |
9 |
Correct |
85 ms |
16972 KB |
Output is correct |
10 |
Correct |
81 ms |
16888 KB |
Output is correct |
11 |
Correct |
86 ms |
16972 KB |
Output is correct |
12 |
Correct |
95 ms |
16968 KB |
Output is correct |
13 |
Correct |
84 ms |
16984 KB |
Output is correct |
14 |
Correct |
80 ms |
16920 KB |
Output is correct |
15 |
Correct |
83 ms |
16992 KB |
Output is correct |
16 |
Correct |
79 ms |
16972 KB |
Output is correct |
17 |
Correct |
88 ms |
16980 KB |
Output is correct |
18 |
Correct |
88 ms |
16956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
16912 KB |
Output is correct |
2 |
Correct |
91 ms |
16984 KB |
Output is correct |
3 |
Correct |
88 ms |
16992 KB |
Output is correct |
4 |
Correct |
77 ms |
16980 KB |
Output is correct |
5 |
Correct |
78 ms |
16856 KB |
Output is correct |
6 |
Correct |
80 ms |
16912 KB |
Output is correct |
7 |
Correct |
81 ms |
16884 KB |
Output is correct |
8 |
Correct |
81 ms |
16972 KB |
Output is correct |
9 |
Correct |
85 ms |
16972 KB |
Output is correct |
10 |
Correct |
81 ms |
16888 KB |
Output is correct |
11 |
Correct |
86 ms |
16972 KB |
Output is correct |
12 |
Correct |
95 ms |
16968 KB |
Output is correct |
13 |
Correct |
84 ms |
16984 KB |
Output is correct |
14 |
Correct |
80 ms |
16920 KB |
Output is correct |
15 |
Correct |
83 ms |
16992 KB |
Output is correct |
16 |
Correct |
79 ms |
16972 KB |
Output is correct |
17 |
Correct |
88 ms |
16980 KB |
Output is correct |
18 |
Correct |
88 ms |
16956 KB |
Output is correct |
19 |
Correct |
374 ms |
46680 KB |
Output is correct |
20 |
Correct |
333 ms |
46728 KB |
Output is correct |
21 |
Correct |
315 ms |
46572 KB |
Output is correct |
22 |
Correct |
274 ms |
49428 KB |
Output is correct |
23 |
Correct |
124 ms |
20724 KB |
Output is correct |
24 |
Correct |
159 ms |
20720 KB |
Output is correct |
25 |
Correct |
303 ms |
49920 KB |
Output is correct |
26 |
Correct |
333 ms |
49924 KB |
Output is correct |
27 |
Correct |
310 ms |
49912 KB |
Output is correct |
28 |
Correct |
355 ms |
49992 KB |
Output is correct |
29 |
Correct |
302 ms |
49908 KB |
Output is correct |
30 |
Correct |
134 ms |
20724 KB |
Output is correct |
31 |
Correct |
310 ms |
49920 KB |
Output is correct |
32 |
Correct |
301 ms |
49632 KB |
Output is correct |
33 |
Correct |
127 ms |
20760 KB |
Output is correct |
34 |
Correct |
325 ms |
49896 KB |
Output is correct |
35 |
Correct |
258 ms |
49148 KB |
Output is correct |
36 |
Correct |
126 ms |
20712 KB |
Output is correct |
37 |
Correct |
128 ms |
20740 KB |
Output is correct |
38 |
Correct |
279 ms |
49696 KB |
Output is correct |
39 |
Correct |
207 ms |
49964 KB |
Output is correct |
40 |
Correct |
243 ms |
34852 KB |
Output is correct |
41 |
Correct |
402 ms |
50364 KB |
Output is correct |
42 |
Correct |
131 ms |
49328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
16912 KB |
Output is correct |
2 |
Correct |
91 ms |
16984 KB |
Output is correct |
3 |
Correct |
88 ms |
16992 KB |
Output is correct |
4 |
Correct |
77 ms |
16980 KB |
Output is correct |
5 |
Correct |
78 ms |
16856 KB |
Output is correct |
6 |
Correct |
80 ms |
16912 KB |
Output is correct |
7 |
Correct |
81 ms |
16884 KB |
Output is correct |
8 |
Correct |
81 ms |
16972 KB |
Output is correct |
9 |
Correct |
85 ms |
16972 KB |
Output is correct |
10 |
Correct |
81 ms |
16888 KB |
Output is correct |
11 |
Correct |
86 ms |
16972 KB |
Output is correct |
12 |
Correct |
95 ms |
16968 KB |
Output is correct |
13 |
Correct |
84 ms |
16984 KB |
Output is correct |
14 |
Correct |
80 ms |
16920 KB |
Output is correct |
15 |
Correct |
83 ms |
16992 KB |
Output is correct |
16 |
Correct |
79 ms |
16972 KB |
Output is correct |
17 |
Correct |
88 ms |
16980 KB |
Output is correct |
18 |
Correct |
88 ms |
16956 KB |
Output is correct |
19 |
Correct |
88 ms |
16844 KB |
Output is correct |
20 |
Correct |
89 ms |
16904 KB |
Output is correct |
21 |
Correct |
83 ms |
16984 KB |
Output is correct |
22 |
Correct |
74 ms |
16944 KB |
Output is correct |
23 |
Correct |
82 ms |
16884 KB |
Output is correct |
24 |
Correct |
79 ms |
16972 KB |
Output is correct |
25 |
Correct |
84 ms |
16980 KB |
Output is correct |
26 |
Correct |
77 ms |
16916 KB |
Output is correct |
27 |
Correct |
82 ms |
16988 KB |
Output is correct |
28 |
Correct |
77 ms |
16924 KB |
Output is correct |
29 |
Correct |
86 ms |
16884 KB |
Output is correct |
30 |
Correct |
78 ms |
16836 KB |
Output is correct |
31 |
Correct |
89 ms |
16996 KB |
Output is correct |
32 |
Correct |
83 ms |
16928 KB |
Output is correct |
33 |
Correct |
86 ms |
17028 KB |
Output is correct |
34 |
Correct |
76 ms |
16848 KB |
Output is correct |
35 |
Correct |
84 ms |
16952 KB |
Output is correct |
36 |
Correct |
84 ms |
16988 KB |
Output is correct |
37 |
Correct |
91 ms |
16960 KB |
Output is correct |
38 |
Correct |
84 ms |
17008 KB |
Output is correct |
39 |
Correct |
82 ms |
16920 KB |
Output is correct |
40 |
Correct |
85 ms |
16940 KB |
Output is correct |
41 |
Correct |
85 ms |
17048 KB |
Output is correct |
42 |
Correct |
84 ms |
16976 KB |
Output is correct |
43 |
Correct |
79 ms |
16964 KB |
Output is correct |
44 |
Correct |
85 ms |
16960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
16912 KB |
Output is correct |
2 |
Correct |
91 ms |
16984 KB |
Output is correct |
3 |
Correct |
88 ms |
16992 KB |
Output is correct |
4 |
Correct |
77 ms |
16980 KB |
Output is correct |
5 |
Correct |
78 ms |
16856 KB |
Output is correct |
6 |
Correct |
80 ms |
16912 KB |
Output is correct |
7 |
Correct |
81 ms |
16884 KB |
Output is correct |
8 |
Correct |
81 ms |
16972 KB |
Output is correct |
9 |
Correct |
85 ms |
16972 KB |
Output is correct |
10 |
Correct |
81 ms |
16888 KB |
Output is correct |
11 |
Correct |
86 ms |
16972 KB |
Output is correct |
12 |
Correct |
95 ms |
16968 KB |
Output is correct |
13 |
Correct |
84 ms |
16984 KB |
Output is correct |
14 |
Correct |
80 ms |
16920 KB |
Output is correct |
15 |
Correct |
83 ms |
16992 KB |
Output is correct |
16 |
Correct |
79 ms |
16972 KB |
Output is correct |
17 |
Correct |
88 ms |
16980 KB |
Output is correct |
18 |
Correct |
88 ms |
16956 KB |
Output is correct |
19 |
Correct |
374 ms |
46680 KB |
Output is correct |
20 |
Correct |
333 ms |
46728 KB |
Output is correct |
21 |
Correct |
315 ms |
46572 KB |
Output is correct |
22 |
Correct |
274 ms |
49428 KB |
Output is correct |
23 |
Correct |
124 ms |
20724 KB |
Output is correct |
24 |
Correct |
159 ms |
20720 KB |
Output is correct |
25 |
Correct |
303 ms |
49920 KB |
Output is correct |
26 |
Correct |
333 ms |
49924 KB |
Output is correct |
27 |
Correct |
310 ms |
49912 KB |
Output is correct |
28 |
Correct |
355 ms |
49992 KB |
Output is correct |
29 |
Correct |
302 ms |
49908 KB |
Output is correct |
30 |
Correct |
134 ms |
20724 KB |
Output is correct |
31 |
Correct |
310 ms |
49920 KB |
Output is correct |
32 |
Correct |
301 ms |
49632 KB |
Output is correct |
33 |
Correct |
127 ms |
20760 KB |
Output is correct |
34 |
Correct |
325 ms |
49896 KB |
Output is correct |
35 |
Correct |
258 ms |
49148 KB |
Output is correct |
36 |
Correct |
126 ms |
20712 KB |
Output is correct |
37 |
Correct |
128 ms |
20740 KB |
Output is correct |
38 |
Correct |
279 ms |
49696 KB |
Output is correct |
39 |
Correct |
207 ms |
49964 KB |
Output is correct |
40 |
Correct |
243 ms |
34852 KB |
Output is correct |
41 |
Correct |
402 ms |
50364 KB |
Output is correct |
42 |
Correct |
131 ms |
49328 KB |
Output is correct |
43 |
Correct |
88 ms |
16844 KB |
Output is correct |
44 |
Correct |
89 ms |
16904 KB |
Output is correct |
45 |
Correct |
83 ms |
16984 KB |
Output is correct |
46 |
Correct |
74 ms |
16944 KB |
Output is correct |
47 |
Correct |
82 ms |
16884 KB |
Output is correct |
48 |
Correct |
79 ms |
16972 KB |
Output is correct |
49 |
Correct |
84 ms |
16980 KB |
Output is correct |
50 |
Correct |
77 ms |
16916 KB |
Output is correct |
51 |
Correct |
82 ms |
16988 KB |
Output is correct |
52 |
Correct |
77 ms |
16924 KB |
Output is correct |
53 |
Correct |
86 ms |
16884 KB |
Output is correct |
54 |
Correct |
78 ms |
16836 KB |
Output is correct |
55 |
Correct |
89 ms |
16996 KB |
Output is correct |
56 |
Correct |
83 ms |
16928 KB |
Output is correct |
57 |
Correct |
86 ms |
17028 KB |
Output is correct |
58 |
Correct |
76 ms |
16848 KB |
Output is correct |
59 |
Correct |
84 ms |
16952 KB |
Output is correct |
60 |
Correct |
84 ms |
16988 KB |
Output is correct |
61 |
Correct |
91 ms |
16960 KB |
Output is correct |
62 |
Correct |
84 ms |
17008 KB |
Output is correct |
63 |
Correct |
82 ms |
16920 KB |
Output is correct |
64 |
Correct |
85 ms |
16940 KB |
Output is correct |
65 |
Correct |
85 ms |
17048 KB |
Output is correct |
66 |
Correct |
84 ms |
16976 KB |
Output is correct |
67 |
Correct |
79 ms |
16964 KB |
Output is correct |
68 |
Correct |
85 ms |
16960 KB |
Output is correct |
69 |
Correct |
344 ms |
49420 KB |
Output is correct |
70 |
Correct |
328 ms |
49828 KB |
Output is correct |
71 |
Correct |
126 ms |
20716 KB |
Output is correct |
72 |
Correct |
126 ms |
20812 KB |
Output is correct |
73 |
Correct |
127 ms |
20812 KB |
Output is correct |
74 |
Correct |
266 ms |
49268 KB |
Output is correct |
75 |
Correct |
130 ms |
20792 KB |
Output is correct |
76 |
Correct |
312 ms |
49940 KB |
Output is correct |
77 |
Correct |
286 ms |
49584 KB |
Output is correct |
78 |
Correct |
130 ms |
20836 KB |
Output is correct |
79 |
Correct |
129 ms |
20812 KB |
Output is correct |
80 |
Correct |
266 ms |
49160 KB |
Output is correct |
81 |
Correct |
125 ms |
20700 KB |
Output is correct |
82 |
Correct |
303 ms |
49912 KB |
Output is correct |
83 |
Correct |
307 ms |
49812 KB |
Output is correct |
84 |
Correct |
131 ms |
20796 KB |
Output is correct |
85 |
Correct |
141 ms |
20772 KB |
Output is correct |
86 |
Correct |
289 ms |
49216 KB |
Output is correct |
87 |
Correct |
324 ms |
49936 KB |
Output is correct |
88 |
Correct |
144 ms |
20844 KB |
Output is correct |
89 |
Correct |
288 ms |
49612 KB |
Output is correct |
90 |
Correct |
322 ms |
49820 KB |
Output is correct |
91 |
Correct |
139 ms |
20716 KB |
Output is correct |
92 |
Correct |
272 ms |
49244 KB |
Output is correct |
93 |
Correct |
126 ms |
20724 KB |
Output is correct |
94 |
Correct |
128 ms |
20756 KB |
Output is correct |
95 |
Correct |
127 ms |
20700 KB |
Output is correct |
96 |
Correct |
291 ms |
49796 KB |
Output is correct |
97 |
Correct |
208 ms |
49944 KB |
Output is correct |
98 |
Correct |
246 ms |
34868 KB |
Output is correct |
99 |
Correct |
417 ms |
50244 KB |
Output is correct |
100 |
Correct |
135 ms |
49324 KB |
Output is correct |