/**
* author: NimaAryan
* created: 2023-12-01 12:26:57
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
using i64 = long long;
constexpr i64 M = 1E9 + 7;
constexpr i64 B = 28463;
vector<i64> powB{1};
vector<vector<i64>> hashC(26);
void init() {
while (powB.size() < 3E5) {
powB.push_back(powB.back() * B % M);
}
for (int i = 0; i < 26; ++i) {
hashC[i].push_back(0);
while (hashC[i].size() < 3E5) {
hashC[i].push_back((hashC[i].back() * B + ('A' + i)) % M);
}
}
}
struct Tag {
char ch = '?';
void apply(const Tag& v) {
if (v.ch != '?') {
ch = v.ch;
}
}
};
struct Info {
int len = 0;
i64 hash = 0;
void apply(int l, int r, const Tag& v) {
if (v.ch != '?') {
len = r - l;
hash = hashC[v.ch - 'A'][len];
}
}
};
Info operator+(Info a, Info b) {
Info res;
res.len = a.len + b.len;
res.hash = (a.hash * powB[b.len] % M + b.hash) % M;
return res;
}
class SegmentTree {
public:
int n;
vector<Info> info;
vector<Tag> tag;
SegmentTree(int n) : n(n) {
info.assign(4 << __lg(n), Info());
tag.assign(4 << __lg(n), Tag());
}
void pull(int p) {
info[p] = info[2 * p] + info[2 * p + 1];
}
void apply(int p, int l, int r, const Tag& v) {
info[p].apply(l, r, v);
tag[p].apply(v);
}
void push(int p, int l, int r) {
int m = (l + r) / 2;
apply(2 * p, l, m, tag[p]);
apply(2 * p + 1, m, r, tag[p]);
tag[p] = Tag();
}
void range_apply(int p, int l, int r, int lx, int rx, const Tag& v) {
if (l >= rx || r <= lx) {
return;
}
if (l >= lx && r <= rx) {
apply(p, l, r, v);
return;
}
push(p, l, r);
int m = (l + r) / 2;
range_apply(2 * p, l, m, lx, rx, v);
range_apply(2 * p + 1, m, r, lx, rx, v);
pull(p);
}
void range_apply(int lx, int rx, const Tag& v) {
range_apply(1, 0, n, lx, rx, v);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int N;
cin >> N;
vector<string> S(3);
for (int i = 0; i < 3; ++i) {
cin >> S[i];
}
set<string> a;
for (int i = 0; i < 3; ++i) {
a.insert(S[i]);
}
while (true) {
auto new_a = a;
for (string s : a) {
for (string t : a) {
if (s != t) {
string u;
for (int i = 0; i < N; ++i) {
if (s[i] == t[i]) {
u.push_back(s[i]);
} else {
set<char> rb{'J', 'O', 'I'};
rb.erase(s[i]);
rb.erase(t[i]);
u.push_back(*rb.begin());
}
}
if (!new_a.count(u)) {
new_a.insert(u);
}
}
}
}
if (a == new_a) {
break;
}
a.swap(new_a);
}
set<i64> search;
for (string s : a) {
i64 hash = 0;
for (int i = 0; i < N; ++i) {
hash = (hash * B + s[i]) % M;
}
search.insert(hash);
}
int Q;
cin >> Q;
string T;
cin >> T;
SegmentTree seg(N);
for (int i = 0; i < N; ++i) {
seg.range_apply(i, i + 1, Tag{T[i]});
}
i64 hash = seg.info[1].hash;
if (search.count(hash)) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
while (Q--) {
int L, R;
cin >> L >> R;
--L;
char C;
cin >> C;
seg.range_apply(L, R, Tag{C});
i64 hash = seg.info[1].hash;
if (search.count(hash)) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
81960 KB |
Output is correct |
2 |
Correct |
157 ms |
67884 KB |
Output is correct |
3 |
Correct |
159 ms |
82424 KB |
Output is correct |
4 |
Correct |
162 ms |
102168 KB |
Output is correct |
5 |
Correct |
169 ms |
113644 KB |
Output is correct |
6 |
Correct |
141 ms |
77456 KB |
Output is correct |
7 |
Correct |
161 ms |
87844 KB |
Output is correct |
8 |
Correct |
171 ms |
109452 KB |
Output is correct |
9 |
Correct |
166 ms |
113340 KB |
Output is correct |
10 |
Correct |
152 ms |
68376 KB |
Output is correct |
11 |
Correct |
149 ms |
92140 KB |
Output is correct |
12 |
Correct |
162 ms |
113464 KB |
Output is correct |
13 |
Correct |
153 ms |
113604 KB |
Output is correct |
14 |
Correct |
157 ms |
80372 KB |
Output is correct |
15 |
Correct |
151 ms |
80412 KB |
Output is correct |
16 |
Correct |
155 ms |
71656 KB |
Output is correct |
17 |
Correct |
156 ms |
81664 KB |
Output is correct |
18 |
Correct |
157 ms |
85040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
81960 KB |
Output is correct |
2 |
Correct |
157 ms |
67884 KB |
Output is correct |
3 |
Correct |
159 ms |
82424 KB |
Output is correct |
4 |
Correct |
162 ms |
102168 KB |
Output is correct |
5 |
Correct |
169 ms |
113644 KB |
Output is correct |
6 |
Correct |
141 ms |
77456 KB |
Output is correct |
7 |
Correct |
161 ms |
87844 KB |
Output is correct |
8 |
Correct |
171 ms |
109452 KB |
Output is correct |
9 |
Correct |
166 ms |
113340 KB |
Output is correct |
10 |
Correct |
152 ms |
68376 KB |
Output is correct |
11 |
Correct |
149 ms |
92140 KB |
Output is correct |
12 |
Correct |
162 ms |
113464 KB |
Output is correct |
13 |
Correct |
153 ms |
113604 KB |
Output is correct |
14 |
Correct |
157 ms |
80372 KB |
Output is correct |
15 |
Correct |
151 ms |
80412 KB |
Output is correct |
16 |
Correct |
155 ms |
71656 KB |
Output is correct |
17 |
Correct |
156 ms |
81664 KB |
Output is correct |
18 |
Correct |
157 ms |
85040 KB |
Output is correct |
19 |
Correct |
325 ms |
103792 KB |
Output is correct |
20 |
Correct |
316 ms |
85632 KB |
Output is correct |
21 |
Correct |
309 ms |
122900 KB |
Output is correct |
22 |
Correct |
255 ms |
104304 KB |
Output is correct |
23 |
Correct |
203 ms |
113432 KB |
Output is correct |
24 |
Correct |
183 ms |
67808 KB |
Output is correct |
25 |
Correct |
258 ms |
102188 KB |
Output is correct |
26 |
Correct |
291 ms |
114816 KB |
Output is correct |
27 |
Correct |
289 ms |
114776 KB |
Output is correct |
28 |
Correct |
324 ms |
98644 KB |
Output is correct |
29 |
Correct |
277 ms |
78436 KB |
Output is correct |
30 |
Correct |
190 ms |
68348 KB |
Output is correct |
31 |
Correct |
288 ms |
122228 KB |
Output is correct |
32 |
Correct |
272 ms |
109396 KB |
Output is correct |
33 |
Correct |
198 ms |
98832 KB |
Output is correct |
34 |
Correct |
284 ms |
117008 KB |
Output is correct |
35 |
Correct |
245 ms |
120820 KB |
Output is correct |
36 |
Correct |
190 ms |
92692 KB |
Output is correct |
37 |
Correct |
206 ms |
71180 KB |
Output is correct |
38 |
Correct |
297 ms |
78024 KB |
Output is correct |
39 |
Correct |
248 ms |
87960 KB |
Output is correct |
40 |
Correct |
243 ms |
86264 KB |
Output is correct |
41 |
Correct |
330 ms |
120664 KB |
Output is correct |
42 |
Correct |
184 ms |
82788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
81960 KB |
Output is correct |
2 |
Correct |
157 ms |
67884 KB |
Output is correct |
3 |
Correct |
159 ms |
82424 KB |
Output is correct |
4 |
Correct |
162 ms |
102168 KB |
Output is correct |
5 |
Correct |
169 ms |
113644 KB |
Output is correct |
6 |
Correct |
141 ms |
77456 KB |
Output is correct |
7 |
Correct |
161 ms |
87844 KB |
Output is correct |
8 |
Correct |
171 ms |
109452 KB |
Output is correct |
9 |
Correct |
166 ms |
113340 KB |
Output is correct |
10 |
Correct |
152 ms |
68376 KB |
Output is correct |
11 |
Correct |
149 ms |
92140 KB |
Output is correct |
12 |
Correct |
162 ms |
113464 KB |
Output is correct |
13 |
Correct |
153 ms |
113604 KB |
Output is correct |
14 |
Correct |
157 ms |
80372 KB |
Output is correct |
15 |
Correct |
151 ms |
80412 KB |
Output is correct |
16 |
Correct |
155 ms |
71656 KB |
Output is correct |
17 |
Correct |
156 ms |
81664 KB |
Output is correct |
18 |
Correct |
157 ms |
85040 KB |
Output is correct |
19 |
Correct |
155 ms |
71780 KB |
Output is correct |
20 |
Correct |
168 ms |
100988 KB |
Output is correct |
21 |
Correct |
159 ms |
102412 KB |
Output is correct |
22 |
Correct |
157 ms |
95992 KB |
Output is correct |
23 |
Correct |
167 ms |
109604 KB |
Output is correct |
24 |
Correct |
155 ms |
85908 KB |
Output is correct |
25 |
Correct |
158 ms |
77920 KB |
Output is correct |
26 |
Correct |
159 ms |
111380 KB |
Output is correct |
27 |
Correct |
161 ms |
90108 KB |
Output is correct |
28 |
Correct |
156 ms |
83708 KB |
Output is correct |
29 |
Correct |
160 ms |
97284 KB |
Output is correct |
30 |
Correct |
144 ms |
67992 KB |
Output is correct |
31 |
Correct |
155 ms |
69024 KB |
Output is correct |
32 |
Correct |
166 ms |
88848 KB |
Output is correct |
33 |
Correct |
157 ms |
71424 KB |
Output is correct |
34 |
Correct |
154 ms |
91920 KB |
Output is correct |
35 |
Correct |
161 ms |
67728 KB |
Output is correct |
36 |
Correct |
154 ms |
72960 KB |
Output is correct |
37 |
Correct |
174 ms |
102108 KB |
Output is correct |
38 |
Correct |
150 ms |
83400 KB |
Output is correct |
39 |
Correct |
159 ms |
85744 KB |
Output is correct |
40 |
Correct |
157 ms |
81168 KB |
Output is correct |
41 |
Correct |
166 ms |
99924 KB |
Output is correct |
42 |
Correct |
175 ms |
112648 KB |
Output is correct |
43 |
Correct |
158 ms |
93996 KB |
Output is correct |
44 |
Correct |
159 ms |
87836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
81960 KB |
Output is correct |
2 |
Correct |
157 ms |
67884 KB |
Output is correct |
3 |
Correct |
159 ms |
82424 KB |
Output is correct |
4 |
Correct |
162 ms |
102168 KB |
Output is correct |
5 |
Correct |
169 ms |
113644 KB |
Output is correct |
6 |
Correct |
141 ms |
77456 KB |
Output is correct |
7 |
Correct |
161 ms |
87844 KB |
Output is correct |
8 |
Correct |
171 ms |
109452 KB |
Output is correct |
9 |
Correct |
166 ms |
113340 KB |
Output is correct |
10 |
Correct |
152 ms |
68376 KB |
Output is correct |
11 |
Correct |
149 ms |
92140 KB |
Output is correct |
12 |
Correct |
162 ms |
113464 KB |
Output is correct |
13 |
Correct |
153 ms |
113604 KB |
Output is correct |
14 |
Correct |
157 ms |
80372 KB |
Output is correct |
15 |
Correct |
151 ms |
80412 KB |
Output is correct |
16 |
Correct |
155 ms |
71656 KB |
Output is correct |
17 |
Correct |
156 ms |
81664 KB |
Output is correct |
18 |
Correct |
157 ms |
85040 KB |
Output is correct |
19 |
Correct |
325 ms |
103792 KB |
Output is correct |
20 |
Correct |
316 ms |
85632 KB |
Output is correct |
21 |
Correct |
309 ms |
122900 KB |
Output is correct |
22 |
Correct |
255 ms |
104304 KB |
Output is correct |
23 |
Correct |
203 ms |
113432 KB |
Output is correct |
24 |
Correct |
183 ms |
67808 KB |
Output is correct |
25 |
Correct |
258 ms |
102188 KB |
Output is correct |
26 |
Correct |
291 ms |
114816 KB |
Output is correct |
27 |
Correct |
289 ms |
114776 KB |
Output is correct |
28 |
Correct |
324 ms |
98644 KB |
Output is correct |
29 |
Correct |
277 ms |
78436 KB |
Output is correct |
30 |
Correct |
190 ms |
68348 KB |
Output is correct |
31 |
Correct |
288 ms |
122228 KB |
Output is correct |
32 |
Correct |
272 ms |
109396 KB |
Output is correct |
33 |
Correct |
198 ms |
98832 KB |
Output is correct |
34 |
Correct |
284 ms |
117008 KB |
Output is correct |
35 |
Correct |
245 ms |
120820 KB |
Output is correct |
36 |
Correct |
190 ms |
92692 KB |
Output is correct |
37 |
Correct |
206 ms |
71180 KB |
Output is correct |
38 |
Correct |
297 ms |
78024 KB |
Output is correct |
39 |
Correct |
248 ms |
87960 KB |
Output is correct |
40 |
Correct |
243 ms |
86264 KB |
Output is correct |
41 |
Correct |
330 ms |
120664 KB |
Output is correct |
42 |
Correct |
184 ms |
82788 KB |
Output is correct |
43 |
Correct |
155 ms |
71780 KB |
Output is correct |
44 |
Correct |
168 ms |
100988 KB |
Output is correct |
45 |
Correct |
159 ms |
102412 KB |
Output is correct |
46 |
Correct |
157 ms |
95992 KB |
Output is correct |
47 |
Correct |
167 ms |
109604 KB |
Output is correct |
48 |
Correct |
155 ms |
85908 KB |
Output is correct |
49 |
Correct |
158 ms |
77920 KB |
Output is correct |
50 |
Correct |
159 ms |
111380 KB |
Output is correct |
51 |
Correct |
161 ms |
90108 KB |
Output is correct |
52 |
Correct |
156 ms |
83708 KB |
Output is correct |
53 |
Correct |
160 ms |
97284 KB |
Output is correct |
54 |
Correct |
144 ms |
67992 KB |
Output is correct |
55 |
Correct |
155 ms |
69024 KB |
Output is correct |
56 |
Correct |
166 ms |
88848 KB |
Output is correct |
57 |
Correct |
157 ms |
71424 KB |
Output is correct |
58 |
Correct |
154 ms |
91920 KB |
Output is correct |
59 |
Correct |
161 ms |
67728 KB |
Output is correct |
60 |
Correct |
154 ms |
72960 KB |
Output is correct |
61 |
Correct |
174 ms |
102108 KB |
Output is correct |
62 |
Correct |
150 ms |
83400 KB |
Output is correct |
63 |
Correct |
159 ms |
85744 KB |
Output is correct |
64 |
Correct |
157 ms |
81168 KB |
Output is correct |
65 |
Correct |
166 ms |
99924 KB |
Output is correct |
66 |
Correct |
175 ms |
112648 KB |
Output is correct |
67 |
Correct |
158 ms |
93996 KB |
Output is correct |
68 |
Correct |
159 ms |
87836 KB |
Output is correct |
69 |
Correct |
1773 ms |
122856 KB |
Output is correct |
70 |
Correct |
2009 ms |
81320 KB |
Output is correct |
71 |
Correct |
226 ms |
112176 KB |
Output is correct |
72 |
Correct |
200 ms |
96696 KB |
Output is correct |
73 |
Correct |
205 ms |
103500 KB |
Output is correct |
74 |
Correct |
336 ms |
118068 KB |
Output is correct |
75 |
Correct |
207 ms |
82944 KB |
Output is correct |
76 |
Correct |
366 ms |
80704 KB |
Output is correct |
77 |
Correct |
332 ms |
78444 KB |
Output is correct |
78 |
Correct |
215 ms |
76828 KB |
Output is correct |
79 |
Correct |
196 ms |
83204 KB |
Output is correct |
80 |
Correct |
1472 ms |
80216 KB |
Output is correct |
81 |
Correct |
281 ms |
79320 KB |
Output is correct |
82 |
Correct |
2004 ms |
108016 KB |
Output is correct |
83 |
Correct |
1851 ms |
85968 KB |
Output is correct |
84 |
Correct |
285 ms |
100100 KB |
Output is correct |
85 |
Correct |
280 ms |
86804 KB |
Output is correct |
86 |
Correct |
1406 ms |
100212 KB |
Output is correct |
87 |
Correct |
1756 ms |
81284 KB |
Output is correct |
88 |
Correct |
285 ms |
97024 KB |
Output is correct |
89 |
Correct |
1611 ms |
112996 KB |
Output is correct |
90 |
Correct |
1877 ms |
103256 KB |
Output is correct |
91 |
Correct |
278 ms |
82220 KB |
Output is correct |
92 |
Correct |
1516 ms |
118932 KB |
Output is correct |
93 |
Correct |
289 ms |
112872 KB |
Output is correct |
94 |
Correct |
286 ms |
108260 KB |
Output is correct |
95 |
Correct |
299 ms |
109600 KB |
Output is correct |
96 |
Correct |
304 ms |
120896 KB |
Output is correct |
97 |
Correct |
316 ms |
106684 KB |
Output is correct |
98 |
Correct |
1345 ms |
79492 KB |
Output is correct |
99 |
Correct |
2013 ms |
88660 KB |
Output is correct |
100 |
Correct |
1894 ms |
82000 KB |
Output is correct |