#include <bits/stdc++.h>
using namespace std;
const array<int, 4> MOD = {
1000000007,
1000000009,
998244353,
420691273,
};
const array<int, 4> KEY = {
7,
37,
67,
97,
};
class SegTree {
public:
int sz;
vector<int> len;
vector<int> lazy;
vector<array<int, 4>> power;
vector<array<array<int, 4>, 4>> hashes;
SegTree(int sz, vector<int> A) : sz(sz) {
power.resize(sz + 1);
power[0] = {1, 1, 1, 1};
for (int i = 1; i <= sz; i++) {
for (int j = 0; j < 4; j++) {
power[i][j] = 1ll * power[i - 1][j] * KEY[j] % MOD[j];
}
}
len.resize(2 * sz);
lazy.resize(2 * sz);
hashes.resize(2 * sz);
Build(1, 0, sz - 1, A);
}
array<int, 4> Merge(array<int, 4> a, array<int, 4> b, int lena) {
array<int, 4> c;
for (int i = 0; i < 4; i++) {
c[i] = (1ll * a[i] + 1ll * b[i] * power[lena][i]) % MOD[i];
}
return c;
}
void Set(int n, int x) {
assert(1 <= x && x <= 3);
hashes[n][0] = hashes[n][x];
lazy[n] = x;
}
void Push(int n, int lc, int rc) {
if (lazy[n]) {
Set(lc, lazy[n]);
Set(rc, lazy[n]);
lazy[n] = 0;
}
}
void Build(int n, int tl, int tr, const vector<int> &A) {
if (tl == tr) {
len[n] = 1;
for (int x = 0; x < 4; x++) {
for (int j = 0; j < 4; j++) {
hashes[n][x][j] = 1ll * (x == 0 ? (A[tl] + 1) : x) * KEY[j] % MOD[j];
}
}
return;
}
int md = (tl + tr) / 2;
int z = n + 2 * (md - tl + 1);
Build(n + 1, tl, md, A);
Build(z, md + 1, tr, A);
len[n] = len[n + 1] + len[z];
for (int x = 0; x < 4; x++) {
hashes[n][x] = Merge(hashes[n + 1][x], hashes[z][x], len[n + 1]);
}
}
void RangeSet(int n, int tl, int tr, int l, int r, int x) {
if (tl > r || l > tr || tl > tr || l > r) return;
if (l <= tl && tr <= r) return Set(n, x);
int md = (tl + tr) / 2;
int z = n + 2 * (md - tl + 1);
Push(n, n + 1, z);
RangeSet(n + 1, tl, md, l, r, x);
RangeSet(z, md + 1, tr, l, r, x);
hashes[n][0] = Merge(hashes[n + 1][0], hashes[z][0], len[n + 1]);
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int N;
cin >> N;
vector<vector<int>> S(3);
for (int i = 0; i < 3; i++) {
string s;
cin >> s;
for (auto x : s) {
if (x == 'J') S[i].push_back(0);
if (x == 'O') S[i].push_back(1);
if (x == 'I') S[i].push_back(2);
}
}
while (true) {
sort(begin(S), end(S));
S.resize(unique(begin(S), end(S)) - begin(S));
bool foundNew = false;
for (auto x : S) if (!foundNew) {
for (auto y : S) if (!foundNew) {
vector<int> res;
for (int i = 0; i < N; i++) {
if (x[i] == y[i]) {
res.push_back(x[i]);
} else {
for (int c = 0; c < 3; c++) {
if (x[i] != c && y[i] != c) {
res.push_back(c);
}
}
}
}
if (!binary_search(begin(S), end(S), res)) {
S.push_back(res);
foundNew = true;
}
}
}
if (!foundNew) {
break;
}
}
assert(S.size() <= 9);
vector<array<int, 4>> hashS;
for (auto s : S) {
hashS.push_back(SegTree(N, s).hashes[1][0]);
}
int Q;
cin >> Q;
vector<int> T;
{
string s;
cin >> s;
for (auto x : s) {
if (x == 'J') T.push_back(0);
if (x == 'O') T.push_back(1);
if (x == 'I') T.push_back(2);
}
}
SegTree seg(N, T);
for (int q = 0; q <= Q; q++) {
if (q > 0) {
int l, r, x;
char c;
cin >> l >> r >> c;
l--, r--;
if (c == 'J') x = 1;
if (c == 'O') x = 2;
if (c == 'I') x = 3;
seg.RangeSet(1, 0, N - 1, l, r, x);
}
bool ans = false;
for (auto s : hashS) {
if (s == seg.hashes[1][0]) {
ans = true;
break;
}
}
if (ans) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:173:19: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
173 | seg.RangeSet(1, 0, N - 1, l, r, x);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
836 KB |
Output is correct |
2 |
Correct |
174 ms |
900 KB |
Output is correct |
3 |
Correct |
182 ms |
852 KB |
Output is correct |
4 |
Correct |
137 ms |
860 KB |
Output is correct |
5 |
Correct |
139 ms |
844 KB |
Output is correct |
6 |
Correct |
137 ms |
804 KB |
Output is correct |
7 |
Correct |
145 ms |
812 KB |
Output is correct |
8 |
Correct |
153 ms |
948 KB |
Output is correct |
9 |
Correct |
157 ms |
896 KB |
Output is correct |
10 |
Correct |
147 ms |
892 KB |
Output is correct |
11 |
Correct |
160 ms |
872 KB |
Output is correct |
12 |
Correct |
143 ms |
880 KB |
Output is correct |
13 |
Correct |
149 ms |
820 KB |
Output is correct |
14 |
Correct |
167 ms |
864 KB |
Output is correct |
15 |
Correct |
148 ms |
968 KB |
Output is correct |
16 |
Correct |
142 ms |
852 KB |
Output is correct |
17 |
Correct |
146 ms |
804 KB |
Output is correct |
18 |
Correct |
161 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
836 KB |
Output is correct |
2 |
Correct |
174 ms |
900 KB |
Output is correct |
3 |
Correct |
182 ms |
852 KB |
Output is correct |
4 |
Correct |
137 ms |
860 KB |
Output is correct |
5 |
Correct |
139 ms |
844 KB |
Output is correct |
6 |
Correct |
137 ms |
804 KB |
Output is correct |
7 |
Correct |
145 ms |
812 KB |
Output is correct |
8 |
Correct |
153 ms |
948 KB |
Output is correct |
9 |
Correct |
157 ms |
896 KB |
Output is correct |
10 |
Correct |
147 ms |
892 KB |
Output is correct |
11 |
Correct |
160 ms |
872 KB |
Output is correct |
12 |
Correct |
143 ms |
880 KB |
Output is correct |
13 |
Correct |
149 ms |
820 KB |
Output is correct |
14 |
Correct |
167 ms |
864 KB |
Output is correct |
15 |
Correct |
148 ms |
968 KB |
Output is correct |
16 |
Correct |
142 ms |
852 KB |
Output is correct |
17 |
Correct |
146 ms |
804 KB |
Output is correct |
18 |
Correct |
161 ms |
856 KB |
Output is correct |
19 |
Correct |
915 ms |
35132 KB |
Output is correct |
20 |
Correct |
795 ms |
35068 KB |
Output is correct |
21 |
Correct |
615 ms |
33020 KB |
Output is correct |
22 |
Correct |
580 ms |
29952 KB |
Output is correct |
23 |
Correct |
304 ms |
2688 KB |
Output is correct |
24 |
Correct |
303 ms |
2648 KB |
Output is correct |
25 |
Correct |
650 ms |
35024 KB |
Output is correct |
26 |
Correct |
630 ms |
35060 KB |
Output is correct |
27 |
Correct |
757 ms |
35080 KB |
Output is correct |
28 |
Correct |
799 ms |
35084 KB |
Output is correct |
29 |
Correct |
745 ms |
34160 KB |
Output is correct |
30 |
Correct |
379 ms |
2740 KB |
Output is correct |
31 |
Correct |
785 ms |
35172 KB |
Output is correct |
32 |
Correct |
742 ms |
32260 KB |
Output is correct |
33 |
Correct |
339 ms |
2628 KB |
Output is correct |
34 |
Correct |
778 ms |
35124 KB |
Output is correct |
35 |
Correct |
549 ms |
26564 KB |
Output is correct |
36 |
Correct |
297 ms |
2648 KB |
Output is correct |
37 |
Correct |
306 ms |
2624 KB |
Output is correct |
38 |
Correct |
683 ms |
35112 KB |
Output is correct |
39 |
Correct |
490 ms |
35116 KB |
Output is correct |
40 |
Correct |
620 ms |
23232 KB |
Output is correct |
41 |
Correct |
984 ms |
35292 KB |
Output is correct |
42 |
Correct |
183 ms |
35276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
836 KB |
Output is correct |
2 |
Correct |
174 ms |
900 KB |
Output is correct |
3 |
Correct |
182 ms |
852 KB |
Output is correct |
4 |
Correct |
137 ms |
860 KB |
Output is correct |
5 |
Correct |
139 ms |
844 KB |
Output is correct |
6 |
Correct |
137 ms |
804 KB |
Output is correct |
7 |
Correct |
145 ms |
812 KB |
Output is correct |
8 |
Correct |
153 ms |
948 KB |
Output is correct |
9 |
Correct |
157 ms |
896 KB |
Output is correct |
10 |
Correct |
147 ms |
892 KB |
Output is correct |
11 |
Correct |
160 ms |
872 KB |
Output is correct |
12 |
Correct |
143 ms |
880 KB |
Output is correct |
13 |
Correct |
149 ms |
820 KB |
Output is correct |
14 |
Correct |
167 ms |
864 KB |
Output is correct |
15 |
Correct |
148 ms |
968 KB |
Output is correct |
16 |
Correct |
142 ms |
852 KB |
Output is correct |
17 |
Correct |
146 ms |
804 KB |
Output is correct |
18 |
Correct |
161 ms |
856 KB |
Output is correct |
19 |
Correct |
175 ms |
836 KB |
Output is correct |
20 |
Correct |
181 ms |
892 KB |
Output is correct |
21 |
Correct |
154 ms |
840 KB |
Output is correct |
22 |
Correct |
140 ms |
860 KB |
Output is correct |
23 |
Correct |
171 ms |
864 KB |
Output is correct |
24 |
Correct |
155 ms |
776 KB |
Output is correct |
25 |
Correct |
160 ms |
848 KB |
Output is correct |
26 |
Correct |
147 ms |
816 KB |
Output is correct |
27 |
Correct |
164 ms |
792 KB |
Output is correct |
28 |
Correct |
141 ms |
756 KB |
Output is correct |
29 |
Correct |
169 ms |
884 KB |
Output is correct |
30 |
Correct |
141 ms |
768 KB |
Output is correct |
31 |
Correct |
152 ms |
916 KB |
Output is correct |
32 |
Correct |
156 ms |
856 KB |
Output is correct |
33 |
Correct |
159 ms |
816 KB |
Output is correct |
34 |
Correct |
132 ms |
776 KB |
Output is correct |
35 |
Correct |
148 ms |
884 KB |
Output is correct |
36 |
Correct |
155 ms |
828 KB |
Output is correct |
37 |
Correct |
177 ms |
856 KB |
Output is correct |
38 |
Correct |
150 ms |
820 KB |
Output is correct |
39 |
Correct |
186 ms |
868 KB |
Output is correct |
40 |
Correct |
155 ms |
896 KB |
Output is correct |
41 |
Correct |
151 ms |
976 KB |
Output is correct |
42 |
Correct |
150 ms |
900 KB |
Output is correct |
43 |
Correct |
158 ms |
872 KB |
Output is correct |
44 |
Correct |
181 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
836 KB |
Output is correct |
2 |
Correct |
174 ms |
900 KB |
Output is correct |
3 |
Correct |
182 ms |
852 KB |
Output is correct |
4 |
Correct |
137 ms |
860 KB |
Output is correct |
5 |
Correct |
139 ms |
844 KB |
Output is correct |
6 |
Correct |
137 ms |
804 KB |
Output is correct |
7 |
Correct |
145 ms |
812 KB |
Output is correct |
8 |
Correct |
153 ms |
948 KB |
Output is correct |
9 |
Correct |
157 ms |
896 KB |
Output is correct |
10 |
Correct |
147 ms |
892 KB |
Output is correct |
11 |
Correct |
160 ms |
872 KB |
Output is correct |
12 |
Correct |
143 ms |
880 KB |
Output is correct |
13 |
Correct |
149 ms |
820 KB |
Output is correct |
14 |
Correct |
167 ms |
864 KB |
Output is correct |
15 |
Correct |
148 ms |
968 KB |
Output is correct |
16 |
Correct |
142 ms |
852 KB |
Output is correct |
17 |
Correct |
146 ms |
804 KB |
Output is correct |
18 |
Correct |
161 ms |
856 KB |
Output is correct |
19 |
Correct |
915 ms |
35132 KB |
Output is correct |
20 |
Correct |
795 ms |
35068 KB |
Output is correct |
21 |
Correct |
615 ms |
33020 KB |
Output is correct |
22 |
Correct |
580 ms |
29952 KB |
Output is correct |
23 |
Correct |
304 ms |
2688 KB |
Output is correct |
24 |
Correct |
303 ms |
2648 KB |
Output is correct |
25 |
Correct |
650 ms |
35024 KB |
Output is correct |
26 |
Correct |
630 ms |
35060 KB |
Output is correct |
27 |
Correct |
757 ms |
35080 KB |
Output is correct |
28 |
Correct |
799 ms |
35084 KB |
Output is correct |
29 |
Correct |
745 ms |
34160 KB |
Output is correct |
30 |
Correct |
379 ms |
2740 KB |
Output is correct |
31 |
Correct |
785 ms |
35172 KB |
Output is correct |
32 |
Correct |
742 ms |
32260 KB |
Output is correct |
33 |
Correct |
339 ms |
2628 KB |
Output is correct |
34 |
Correct |
778 ms |
35124 KB |
Output is correct |
35 |
Correct |
549 ms |
26564 KB |
Output is correct |
36 |
Correct |
297 ms |
2648 KB |
Output is correct |
37 |
Correct |
306 ms |
2624 KB |
Output is correct |
38 |
Correct |
683 ms |
35112 KB |
Output is correct |
39 |
Correct |
490 ms |
35116 KB |
Output is correct |
40 |
Correct |
620 ms |
23232 KB |
Output is correct |
41 |
Correct |
984 ms |
35292 KB |
Output is correct |
42 |
Correct |
183 ms |
35276 KB |
Output is correct |
43 |
Correct |
175 ms |
836 KB |
Output is correct |
44 |
Correct |
181 ms |
892 KB |
Output is correct |
45 |
Correct |
154 ms |
840 KB |
Output is correct |
46 |
Correct |
140 ms |
860 KB |
Output is correct |
47 |
Correct |
171 ms |
864 KB |
Output is correct |
48 |
Correct |
155 ms |
776 KB |
Output is correct |
49 |
Correct |
160 ms |
848 KB |
Output is correct |
50 |
Correct |
147 ms |
816 KB |
Output is correct |
51 |
Correct |
164 ms |
792 KB |
Output is correct |
52 |
Correct |
141 ms |
756 KB |
Output is correct |
53 |
Correct |
169 ms |
884 KB |
Output is correct |
54 |
Correct |
141 ms |
768 KB |
Output is correct |
55 |
Correct |
152 ms |
916 KB |
Output is correct |
56 |
Correct |
156 ms |
856 KB |
Output is correct |
57 |
Correct |
159 ms |
816 KB |
Output is correct |
58 |
Correct |
132 ms |
776 KB |
Output is correct |
59 |
Correct |
148 ms |
884 KB |
Output is correct |
60 |
Correct |
155 ms |
828 KB |
Output is correct |
61 |
Correct |
177 ms |
856 KB |
Output is correct |
62 |
Correct |
150 ms |
820 KB |
Output is correct |
63 |
Correct |
186 ms |
868 KB |
Output is correct |
64 |
Correct |
155 ms |
896 KB |
Output is correct |
65 |
Correct |
151 ms |
976 KB |
Output is correct |
66 |
Correct |
150 ms |
900 KB |
Output is correct |
67 |
Correct |
158 ms |
872 KB |
Output is correct |
68 |
Correct |
181 ms |
900 KB |
Output is correct |
69 |
Correct |
1712 ms |
35812 KB |
Output is correct |
70 |
Correct |
1822 ms |
41768 KB |
Output is correct |
71 |
Correct |
316 ms |
2708 KB |
Output is correct |
72 |
Correct |
324 ms |
2828 KB |
Output is correct |
73 |
Correct |
294 ms |
2820 KB |
Output is correct |
74 |
Correct |
720 ms |
31228 KB |
Output is correct |
75 |
Correct |
307 ms |
2752 KB |
Output is correct |
76 |
Correct |
929 ms |
36900 KB |
Output is correct |
77 |
Correct |
782 ms |
31372 KB |
Output is correct |
78 |
Correct |
289 ms |
2748 KB |
Output is correct |
79 |
Correct |
311 ms |
2716 KB |
Output is correct |
80 |
Correct |
1220 ms |
30772 KB |
Output is correct |
81 |
Correct |
337 ms |
2968 KB |
Output is correct |
82 |
Correct |
1581 ms |
41828 KB |
Output is correct |
83 |
Correct |
1580 ms |
39932 KB |
Output is correct |
84 |
Correct |
356 ms |
3016 KB |
Output is correct |
85 |
Correct |
348 ms |
2976 KB |
Output is correct |
86 |
Correct |
1351 ms |
32708 KB |
Output is correct |
87 |
Correct |
1507 ms |
41748 KB |
Output is correct |
88 |
Correct |
366 ms |
3156 KB |
Output is correct |
89 |
Correct |
1272 ms |
37540 KB |
Output is correct |
90 |
Correct |
1509 ms |
41868 KB |
Output is correct |
91 |
Correct |
347 ms |
2936 KB |
Output is correct |
92 |
Correct |
1248 ms |
32216 KB |
Output is correct |
93 |
Correct |
355 ms |
2976 KB |
Output is correct |
94 |
Correct |
337 ms |
2984 KB |
Output is correct |
95 |
Correct |
346 ms |
3004 KB |
Output is correct |
96 |
Correct |
678 ms |
35068 KB |
Output is correct |
97 |
Correct |
1144 ms |
41760 KB |
Output is correct |
98 |
Correct |
1158 ms |
28292 KB |
Output is correct |
99 |
Correct |
1965 ms |
42032 KB |
Output is correct |
100 |
Correct |
1161 ms |
42016 KB |
Output is correct |