#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]);
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 |
78 ms |
17908 KB |
Output is correct |
2 |
Correct |
85 ms |
18112 KB |
Output is correct |
3 |
Correct |
86 ms |
17964 KB |
Output is correct |
4 |
Correct |
78 ms |
18052 KB |
Output is correct |
5 |
Correct |
76 ms |
18072 KB |
Output is correct |
6 |
Correct |
79 ms |
17972 KB |
Output is correct |
7 |
Correct |
79 ms |
18064 KB |
Output is correct |
8 |
Correct |
85 ms |
18108 KB |
Output is correct |
9 |
Correct |
79 ms |
18120 KB |
Output is correct |
10 |
Correct |
79 ms |
18092 KB |
Output is correct |
11 |
Correct |
83 ms |
18112 KB |
Output is correct |
12 |
Correct |
87 ms |
18192 KB |
Output is correct |
13 |
Correct |
80 ms |
18076 KB |
Output is correct |
14 |
Correct |
92 ms |
18144 KB |
Output is correct |
15 |
Correct |
82 ms |
18096 KB |
Output is correct |
16 |
Correct |
83 ms |
18124 KB |
Output is correct |
17 |
Correct |
80 ms |
18052 KB |
Output is correct |
18 |
Correct |
84 ms |
18032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
17908 KB |
Output is correct |
2 |
Correct |
85 ms |
18112 KB |
Output is correct |
3 |
Correct |
86 ms |
17964 KB |
Output is correct |
4 |
Correct |
78 ms |
18052 KB |
Output is correct |
5 |
Correct |
76 ms |
18072 KB |
Output is correct |
6 |
Correct |
79 ms |
17972 KB |
Output is correct |
7 |
Correct |
79 ms |
18064 KB |
Output is correct |
8 |
Correct |
85 ms |
18108 KB |
Output is correct |
9 |
Correct |
79 ms |
18120 KB |
Output is correct |
10 |
Correct |
79 ms |
18092 KB |
Output is correct |
11 |
Correct |
83 ms |
18112 KB |
Output is correct |
12 |
Correct |
87 ms |
18192 KB |
Output is correct |
13 |
Correct |
80 ms |
18076 KB |
Output is correct |
14 |
Correct |
92 ms |
18144 KB |
Output is correct |
15 |
Correct |
82 ms |
18096 KB |
Output is correct |
16 |
Correct |
83 ms |
18124 KB |
Output is correct |
17 |
Correct |
80 ms |
18052 KB |
Output is correct |
18 |
Correct |
84 ms |
18032 KB |
Output is correct |
19 |
Correct |
384 ms |
53720 KB |
Output is correct |
20 |
Correct |
336 ms |
53448 KB |
Output is correct |
21 |
Incorrect |
277 ms |
53316 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
17908 KB |
Output is correct |
2 |
Correct |
85 ms |
18112 KB |
Output is correct |
3 |
Correct |
86 ms |
17964 KB |
Output is correct |
4 |
Correct |
78 ms |
18052 KB |
Output is correct |
5 |
Correct |
76 ms |
18072 KB |
Output is correct |
6 |
Correct |
79 ms |
17972 KB |
Output is correct |
7 |
Correct |
79 ms |
18064 KB |
Output is correct |
8 |
Correct |
85 ms |
18108 KB |
Output is correct |
9 |
Correct |
79 ms |
18120 KB |
Output is correct |
10 |
Correct |
79 ms |
18092 KB |
Output is correct |
11 |
Correct |
83 ms |
18112 KB |
Output is correct |
12 |
Correct |
87 ms |
18192 KB |
Output is correct |
13 |
Correct |
80 ms |
18076 KB |
Output is correct |
14 |
Correct |
92 ms |
18144 KB |
Output is correct |
15 |
Correct |
82 ms |
18096 KB |
Output is correct |
16 |
Correct |
83 ms |
18124 KB |
Output is correct |
17 |
Correct |
80 ms |
18052 KB |
Output is correct |
18 |
Correct |
84 ms |
18032 KB |
Output is correct |
19 |
Correct |
85 ms |
17972 KB |
Output is correct |
20 |
Correct |
94 ms |
17996 KB |
Output is correct |
21 |
Correct |
85 ms |
18048 KB |
Output is correct |
22 |
Correct |
70 ms |
17880 KB |
Output is correct |
23 |
Correct |
83 ms |
18120 KB |
Output is correct |
24 |
Correct |
86 ms |
18004 KB |
Output is correct |
25 |
Correct |
83 ms |
18124 KB |
Output is correct |
26 |
Correct |
79 ms |
18000 KB |
Output is correct |
27 |
Correct |
84 ms |
18232 KB |
Output is correct |
28 |
Correct |
74 ms |
17908 KB |
Output is correct |
29 |
Correct |
81 ms |
18124 KB |
Output is correct |
30 |
Correct |
74 ms |
17888 KB |
Output is correct |
31 |
Correct |
84 ms |
18160 KB |
Output is correct |
32 |
Correct |
82 ms |
18060 KB |
Output is correct |
33 |
Correct |
83 ms |
18064 KB |
Output is correct |
34 |
Correct |
75 ms |
17928 KB |
Output is correct |
35 |
Correct |
80 ms |
18144 KB |
Output is correct |
36 |
Correct |
83 ms |
18056 KB |
Output is correct |
37 |
Correct |
83 ms |
18124 KB |
Output is correct |
38 |
Correct |
82 ms |
18192 KB |
Output is correct |
39 |
Correct |
79 ms |
18132 KB |
Output is correct |
40 |
Correct |
82 ms |
18036 KB |
Output is correct |
41 |
Correct |
87 ms |
18120 KB |
Output is correct |
42 |
Correct |
84 ms |
18116 KB |
Output is correct |
43 |
Correct |
79 ms |
18012 KB |
Output is correct |
44 |
Correct |
100 ms |
18124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
17908 KB |
Output is correct |
2 |
Correct |
85 ms |
18112 KB |
Output is correct |
3 |
Correct |
86 ms |
17964 KB |
Output is correct |
4 |
Correct |
78 ms |
18052 KB |
Output is correct |
5 |
Correct |
76 ms |
18072 KB |
Output is correct |
6 |
Correct |
79 ms |
17972 KB |
Output is correct |
7 |
Correct |
79 ms |
18064 KB |
Output is correct |
8 |
Correct |
85 ms |
18108 KB |
Output is correct |
9 |
Correct |
79 ms |
18120 KB |
Output is correct |
10 |
Correct |
79 ms |
18092 KB |
Output is correct |
11 |
Correct |
83 ms |
18112 KB |
Output is correct |
12 |
Correct |
87 ms |
18192 KB |
Output is correct |
13 |
Correct |
80 ms |
18076 KB |
Output is correct |
14 |
Correct |
92 ms |
18144 KB |
Output is correct |
15 |
Correct |
82 ms |
18096 KB |
Output is correct |
16 |
Correct |
83 ms |
18124 KB |
Output is correct |
17 |
Correct |
80 ms |
18052 KB |
Output is correct |
18 |
Correct |
84 ms |
18032 KB |
Output is correct |
19 |
Correct |
384 ms |
53720 KB |
Output is correct |
20 |
Correct |
336 ms |
53448 KB |
Output is correct |
21 |
Incorrect |
277 ms |
53316 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |