/**
* 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(3, {0});
void init() {
while (powB.size() < 3E5) {
powB.push_back(powB.back() * B % M);
}
for (int i = 0; i < 3; ++i) {
while (hashC[i].size() < 3E5) {
hashC[i].push_back((hashC[i].back() * B + i) % M);
}
}
}
struct Tag {
int ch = -1;
void apply(const Tag& v) {
if (v.ch != -1) {
ch = v.ch;
}
}
};
struct Info {
int len = 0;
i64 hash = 0;
void apply(int l, int r, const Tag& v) {
if (v.ch != -1) {
len = r - l;
hash = hashC[v.ch][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 asc(char c) {
return c == 'J' ? 0 : (c == 'O' ? 1 : 2);
}
vector<int> conv(string s) {
vector<int> res;
for (int i = 0; i < s.size(); ++i) {
res.push_back(asc(s[i]));
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int N;
cin >> N;
vector<vector<int>> S(3);
for (int i = 0; i < 3; ++i) {
string t;
cin >> t;
S[i] = conv(t);
}
set<vector<int>> a;
for (int i = 0; i < 3; ++i) {
a.insert(S[i]);
}
while (true) {
auto new_a = a;
for (auto s : a) {
for (auto t : a) {
if (s != t) {
vector<int> u;
for (int i = 0; i < N; ++i) {
u.push_back((6 - (s[i] + t[i])) % 3);
}
if (!new_a.count(u)) {
new_a.insert(u);
}
}
}
}
if (a == new_a) {
break;
}
a.swap(new_a);
}
set<i64> search;
for (auto 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;
auto t = conv(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{asc(C)});
i64 hash = seg.info[1].hash;
if (search.count(hash)) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
}
return 0;
}
Compilation message
Main.cpp: In function 'std::vector<int> conv(std::string)':
Main.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for (int i = 0; i < s.size(); ++i) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
15064 KB |
Output is correct |
2 |
Correct |
75 ms |
15284 KB |
Output is correct |
3 |
Correct |
76 ms |
18648 KB |
Output is correct |
4 |
Correct |
66 ms |
14032 KB |
Output is correct |
5 |
Correct |
66 ms |
16600 KB |
Output is correct |
6 |
Correct |
67 ms |
20184 KB |
Output is correct |
7 |
Correct |
69 ms |
20180 KB |
Output is correct |
8 |
Correct |
77 ms |
18900 KB |
Output is correct |
9 |
Correct |
69 ms |
14808 KB |
Output is correct |
10 |
Correct |
71 ms |
20696 KB |
Output is correct |
11 |
Correct |
73 ms |
19416 KB |
Output is correct |
12 |
Correct |
72 ms |
20440 KB |
Output is correct |
13 |
Correct |
71 ms |
16344 KB |
Output is correct |
14 |
Correct |
70 ms |
19936 KB |
Output is correct |
15 |
Correct |
71 ms |
14040 KB |
Output is correct |
16 |
Correct |
76 ms |
15320 KB |
Output is correct |
17 |
Correct |
70 ms |
15240 KB |
Output is correct |
18 |
Correct |
71 ms |
17108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
15064 KB |
Output is correct |
2 |
Correct |
75 ms |
15284 KB |
Output is correct |
3 |
Correct |
76 ms |
18648 KB |
Output is correct |
4 |
Correct |
66 ms |
14032 KB |
Output is correct |
5 |
Correct |
66 ms |
16600 KB |
Output is correct |
6 |
Correct |
67 ms |
20184 KB |
Output is correct |
7 |
Correct |
69 ms |
20180 KB |
Output is correct |
8 |
Correct |
77 ms |
18900 KB |
Output is correct |
9 |
Correct |
69 ms |
14808 KB |
Output is correct |
10 |
Correct |
71 ms |
20696 KB |
Output is correct |
11 |
Correct |
73 ms |
19416 KB |
Output is correct |
12 |
Correct |
72 ms |
20440 KB |
Output is correct |
13 |
Correct |
71 ms |
16344 KB |
Output is correct |
14 |
Correct |
70 ms |
19936 KB |
Output is correct |
15 |
Correct |
71 ms |
14040 KB |
Output is correct |
16 |
Correct |
76 ms |
15320 KB |
Output is correct |
17 |
Correct |
70 ms |
15240 KB |
Output is correct |
18 |
Correct |
71 ms |
17108 KB |
Output is correct |
19 |
Correct |
227 ms |
32152 KB |
Output is correct |
20 |
Correct |
236 ms |
30560 KB |
Output is correct |
21 |
Correct |
176 ms |
26264 KB |
Output is correct |
22 |
Correct |
174 ms |
29476 KB |
Output is correct |
23 |
Correct |
107 ms |
19160 KB |
Output is correct |
24 |
Correct |
103 ms |
14036 KB |
Output is correct |
25 |
Correct |
189 ms |
33240 KB |
Output is correct |
26 |
Correct |
190 ms |
27696 KB |
Output is correct |
27 |
Correct |
200 ms |
29652 KB |
Output is correct |
28 |
Correct |
204 ms |
28468 KB |
Output is correct |
29 |
Correct |
197 ms |
26416 KB |
Output is correct |
30 |
Correct |
110 ms |
13524 KB |
Output is correct |
31 |
Correct |
204 ms |
31384 KB |
Output is correct |
32 |
Correct |
194 ms |
30708 KB |
Output is correct |
33 |
Correct |
106 ms |
18388 KB |
Output is correct |
34 |
Correct |
199 ms |
32884 KB |
Output is correct |
35 |
Correct |
159 ms |
26420 KB |
Output is correct |
36 |
Correct |
104 ms |
20692 KB |
Output is correct |
37 |
Correct |
103 ms |
15060 KB |
Output is correct |
38 |
Correct |
205 ms |
27320 KB |
Output is correct |
39 |
Correct |
173 ms |
31792 KB |
Output is correct |
40 |
Correct |
169 ms |
29740 KB |
Output is correct |
41 |
Correct |
236 ms |
26792 KB |
Output is correct |
42 |
Correct |
105 ms |
26800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
15064 KB |
Output is correct |
2 |
Correct |
75 ms |
15284 KB |
Output is correct |
3 |
Correct |
76 ms |
18648 KB |
Output is correct |
4 |
Correct |
66 ms |
14032 KB |
Output is correct |
5 |
Correct |
66 ms |
16600 KB |
Output is correct |
6 |
Correct |
67 ms |
20184 KB |
Output is correct |
7 |
Correct |
69 ms |
20180 KB |
Output is correct |
8 |
Correct |
77 ms |
18900 KB |
Output is correct |
9 |
Correct |
69 ms |
14808 KB |
Output is correct |
10 |
Correct |
71 ms |
20696 KB |
Output is correct |
11 |
Correct |
73 ms |
19416 KB |
Output is correct |
12 |
Correct |
72 ms |
20440 KB |
Output is correct |
13 |
Correct |
71 ms |
16344 KB |
Output is correct |
14 |
Correct |
70 ms |
19936 KB |
Output is correct |
15 |
Correct |
71 ms |
14040 KB |
Output is correct |
16 |
Correct |
76 ms |
15320 KB |
Output is correct |
17 |
Correct |
70 ms |
15240 KB |
Output is correct |
18 |
Correct |
71 ms |
17108 KB |
Output is correct |
19 |
Correct |
81 ms |
18644 KB |
Output is correct |
20 |
Correct |
81 ms |
16344 KB |
Output is correct |
21 |
Correct |
72 ms |
14552 KB |
Output is correct |
22 |
Correct |
71 ms |
15064 KB |
Output is correct |
23 |
Correct |
71 ms |
19160 KB |
Output is correct |
24 |
Correct |
70 ms |
17596 KB |
Output is correct |
25 |
Correct |
73 ms |
17876 KB |
Output is correct |
26 |
Correct |
67 ms |
15316 KB |
Output is correct |
27 |
Correct |
76 ms |
14296 KB |
Output is correct |
28 |
Correct |
66 ms |
16344 KB |
Output is correct |
29 |
Correct |
74 ms |
18136 KB |
Output is correct |
30 |
Correct |
65 ms |
14968 KB |
Output is correct |
31 |
Correct |
75 ms |
13784 KB |
Output is correct |
32 |
Correct |
85 ms |
17880 KB |
Output is correct |
33 |
Correct |
74 ms |
16904 KB |
Output is correct |
34 |
Correct |
69 ms |
20104 KB |
Output is correct |
35 |
Correct |
75 ms |
16992 KB |
Output is correct |
36 |
Correct |
76 ms |
14040 KB |
Output is correct |
37 |
Correct |
75 ms |
16084 KB |
Output is correct |
38 |
Correct |
76 ms |
19416 KB |
Output is correct |
39 |
Correct |
75 ms |
19744 KB |
Output is correct |
40 |
Correct |
77 ms |
19928 KB |
Output is correct |
41 |
Correct |
74 ms |
18900 KB |
Output is correct |
42 |
Correct |
73 ms |
14548 KB |
Output is correct |
43 |
Correct |
72 ms |
15316 KB |
Output is correct |
44 |
Correct |
75 ms |
17368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
15064 KB |
Output is correct |
2 |
Correct |
75 ms |
15284 KB |
Output is correct |
3 |
Correct |
76 ms |
18648 KB |
Output is correct |
4 |
Correct |
66 ms |
14032 KB |
Output is correct |
5 |
Correct |
66 ms |
16600 KB |
Output is correct |
6 |
Correct |
67 ms |
20184 KB |
Output is correct |
7 |
Correct |
69 ms |
20180 KB |
Output is correct |
8 |
Correct |
77 ms |
18900 KB |
Output is correct |
9 |
Correct |
69 ms |
14808 KB |
Output is correct |
10 |
Correct |
71 ms |
20696 KB |
Output is correct |
11 |
Correct |
73 ms |
19416 KB |
Output is correct |
12 |
Correct |
72 ms |
20440 KB |
Output is correct |
13 |
Correct |
71 ms |
16344 KB |
Output is correct |
14 |
Correct |
70 ms |
19936 KB |
Output is correct |
15 |
Correct |
71 ms |
14040 KB |
Output is correct |
16 |
Correct |
76 ms |
15320 KB |
Output is correct |
17 |
Correct |
70 ms |
15240 KB |
Output is correct |
18 |
Correct |
71 ms |
17108 KB |
Output is correct |
19 |
Correct |
227 ms |
32152 KB |
Output is correct |
20 |
Correct |
236 ms |
30560 KB |
Output is correct |
21 |
Correct |
176 ms |
26264 KB |
Output is correct |
22 |
Correct |
174 ms |
29476 KB |
Output is correct |
23 |
Correct |
107 ms |
19160 KB |
Output is correct |
24 |
Correct |
103 ms |
14036 KB |
Output is correct |
25 |
Correct |
189 ms |
33240 KB |
Output is correct |
26 |
Correct |
190 ms |
27696 KB |
Output is correct |
27 |
Correct |
200 ms |
29652 KB |
Output is correct |
28 |
Correct |
204 ms |
28468 KB |
Output is correct |
29 |
Correct |
197 ms |
26416 KB |
Output is correct |
30 |
Correct |
110 ms |
13524 KB |
Output is correct |
31 |
Correct |
204 ms |
31384 KB |
Output is correct |
32 |
Correct |
194 ms |
30708 KB |
Output is correct |
33 |
Correct |
106 ms |
18388 KB |
Output is correct |
34 |
Correct |
199 ms |
32884 KB |
Output is correct |
35 |
Correct |
159 ms |
26420 KB |
Output is correct |
36 |
Correct |
104 ms |
20692 KB |
Output is correct |
37 |
Correct |
103 ms |
15060 KB |
Output is correct |
38 |
Correct |
205 ms |
27320 KB |
Output is correct |
39 |
Correct |
173 ms |
31792 KB |
Output is correct |
40 |
Correct |
169 ms |
29740 KB |
Output is correct |
41 |
Correct |
236 ms |
26792 KB |
Output is correct |
42 |
Correct |
105 ms |
26800 KB |
Output is correct |
43 |
Correct |
81 ms |
18644 KB |
Output is correct |
44 |
Correct |
81 ms |
16344 KB |
Output is correct |
45 |
Correct |
72 ms |
14552 KB |
Output is correct |
46 |
Correct |
71 ms |
15064 KB |
Output is correct |
47 |
Correct |
71 ms |
19160 KB |
Output is correct |
48 |
Correct |
70 ms |
17596 KB |
Output is correct |
49 |
Correct |
73 ms |
17876 KB |
Output is correct |
50 |
Correct |
67 ms |
15316 KB |
Output is correct |
51 |
Correct |
76 ms |
14296 KB |
Output is correct |
52 |
Correct |
66 ms |
16344 KB |
Output is correct |
53 |
Correct |
74 ms |
18136 KB |
Output is correct |
54 |
Correct |
65 ms |
14968 KB |
Output is correct |
55 |
Correct |
75 ms |
13784 KB |
Output is correct |
56 |
Correct |
85 ms |
17880 KB |
Output is correct |
57 |
Correct |
74 ms |
16904 KB |
Output is correct |
58 |
Correct |
69 ms |
20104 KB |
Output is correct |
59 |
Correct |
75 ms |
16992 KB |
Output is correct |
60 |
Correct |
76 ms |
14040 KB |
Output is correct |
61 |
Correct |
75 ms |
16084 KB |
Output is correct |
62 |
Correct |
76 ms |
19416 KB |
Output is correct |
63 |
Correct |
75 ms |
19744 KB |
Output is correct |
64 |
Correct |
77 ms |
19928 KB |
Output is correct |
65 |
Correct |
74 ms |
18900 KB |
Output is correct |
66 |
Correct |
73 ms |
14548 KB |
Output is correct |
67 |
Correct |
72 ms |
15316 KB |
Output is correct |
68 |
Correct |
75 ms |
17368 KB |
Output is correct |
69 |
Correct |
282 ms |
36912 KB |
Output is correct |
70 |
Correct |
331 ms |
40568 KB |
Output is correct |
71 |
Correct |
110 ms |
20440 KB |
Output is correct |
72 |
Correct |
107 ms |
18900 KB |
Output is correct |
73 |
Correct |
107 ms |
14552 KB |
Output is correct |
74 |
Correct |
183 ms |
27040 KB |
Output is correct |
75 |
Correct |
118 ms |
18392 KB |
Output is correct |
76 |
Correct |
198 ms |
33876 KB |
Output is correct |
77 |
Correct |
182 ms |
31072 KB |
Output is correct |
78 |
Correct |
108 ms |
13784 KB |
Output is correct |
79 |
Correct |
108 ms |
20436 KB |
Output is correct |
80 |
Correct |
232 ms |
37352 KB |
Output is correct |
81 |
Correct |
112 ms |
16852 KB |
Output is correct |
82 |
Correct |
277 ms |
39728 KB |
Output is correct |
83 |
Correct |
264 ms |
37680 KB |
Output is correct |
84 |
Correct |
114 ms |
20440 KB |
Output is correct |
85 |
Correct |
117 ms |
17880 KB |
Output is correct |
86 |
Correct |
246 ms |
34100 KB |
Output is correct |
87 |
Correct |
292 ms |
39180 KB |
Output is correct |
88 |
Correct |
120 ms |
18648 KB |
Output is correct |
89 |
Correct |
262 ms |
41584 KB |
Output is correct |
90 |
Correct |
306 ms |
41580 KB |
Output is correct |
91 |
Correct |
115 ms |
19684 KB |
Output is correct |
92 |
Correct |
234 ms |
33816 KB |
Output is correct |
93 |
Correct |
114 ms |
20436 KB |
Output is correct |
94 |
Correct |
111 ms |
14040 KB |
Output is correct |
95 |
Correct |
114 ms |
13856 KB |
Output is correct |
96 |
Correct |
207 ms |
28784 KB |
Output is correct |
97 |
Correct |
281 ms |
39452 KB |
Output is correct |
98 |
Correct |
220 ms |
31588 KB |
Output is correct |
99 |
Correct |
350 ms |
45528 KB |
Output is correct |
100 |
Correct |
198 ms |
43568 KB |
Output is correct |