#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int N = 2e5 + 8, base = 7;
const ll mod = 10'000'000'000'000'061;
int n;
string sa, sb, sc;
ll add(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
ll ha, hb, hc, pw[N], prf[N];
int ch[256], mer[256][256];
void init_hsh() {
pw[0] = prf[0] = 1;
for (int i = 1; i <= n; ++i) {
pw[i] = pw[i - 1] * base % mod;
prf[i] = add(prf[i - 1], pw[i]);
}
ch['J'] = 1, ch['O'] = 2, ch['I'] = 3;
mer['J']['O'] = mer['O']['J'] = mer['I']['I'] = 'I';
mer['J']['I'] = mer['I']['J'] = mer['O']['O'] = 'O';
mer['I']['O'] = mer['O']['I'] = mer['J']['J'] = 'J';
for (int i = 0; i < n; ++i) {
ha = (ha + ch[sa[i]] * pw[i]) % mod;
hb = (hb + ch[sb[i]] * pw[i]) % mod;
hc = (hc + ch[sc[i]] * pw[i]) % mod;
}
}
ll gethsh(string s) {
ll hsh(0);
for (int i = 0; i < n; ++i)
hsh = (hsh + ch[s[i]] * pw[i]) % mod;
return hsh;
}
string Merge(string a, string b) {
string c;
for (int i = 0; i < n; ++i)
c.push_back(mer[a[i]][b[i]]);
return c;
}
unordered_set<ll> S;
void build_S() {
vector<string> q[2];
q[0].push_back(sa); S.insert(ha);
q[0].push_back(sb); S.insert(hb);
q[0].push_back(sc); S.insert(hc);
while (!q[0].empty()) {
string str = q[0].back(); q[0].pop_back();
for (string str1 : q[1]) {
string str2 = Merge(str, str1);
ll hsh = gethsh(str2);
if (!S.count(hsh)) {
q[0].push_back(str2); S.insert(hsh);
}
}
q[1].push_back(str);
}
}
int q;
string t;
ll seg[N << 2];
int laz[N << 2];
void build(int u, int l, int r) {
if (l == r) {
seg[u] = ch[t[l]] * pw[l] % mod;
return;
}
int m = (l + r) >> 1, u1 = u << 1, u2 = u1 | 1;
build(u1, l, m);
build(u2, m + 1, r);
seg[u] = add(seg[u1], seg[u2]);
}
void upd(int u, int l, int r, int a, int b, int x) {
if (a <= l && r <= b) {
seg[u] = x * (prf[r] - prf[l] + pw[l] + mod) % mod;
laz[u] = x;
return;
}
int m = (l + r) >> 1, u1 = u << 1, u2 = u1 | 1;
if (laz[u]) {
seg[u1] = laz[u] * (prf[m] - prf[l] + pw[l] + mod) % mod;
seg[u2] = laz[u] * (prf[r] - prf[m] + mod) % mod;
laz[u1] = laz[u2] = laz[u];
laz[u] = 0;
}
if (a <= m) upd(u1, l, m, a, b, x);
if (m < b) upd(u2, m + 1, r, a, b, x);
seg[u] = add(seg[u1], seg[u2]);
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> sa >> sb >> sc;
init_hsh();
build_S();
cin >> q >> t;
build(1, 0, n - 1);
cout << (S.count(seg[1]) ? "Yes\n" : "No\n");
int l, r; char c; while (q--) {
cin >> l >> r >> c;
upd(1, 0, n - 1, l - 1, r - 1, ch[c]);
cout << (S.count(seg[1]) ? "Yes\n" : "No\n");
}
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
Compilation message
Main.cpp: In function 'void init_hsh()':
Main.cpp:29:28: warning: array subscript has type 'char' [-Wchar-subscripts]
29 | ha = (ha + ch[sa[i]] * pw[i]) % mod;
| ^
Main.cpp:30:28: warning: array subscript has type 'char' [-Wchar-subscripts]
30 | hb = (hb + ch[sb[i]] * pw[i]) % mod;
| ^
Main.cpp:31:28: warning: array subscript has type 'char' [-Wchar-subscripts]
31 | hc = (hc + ch[sc[i]] * pw[i]) % mod;
| ^
Main.cpp: In function 'll gethsh(std::string)':
Main.cpp:37:29: warning: array subscript has type 'char' [-Wchar-subscripts]
37 | hsh = (hsh + ch[s[i]] * pw[i]) % mod;
| ^
Main.cpp: In function 'std::string Merge(std::string, std::string)':
Main.cpp:43:29: warning: array subscript has type 'char' [-Wchar-subscripts]
43 | c.push_back(mer[a[i]][b[i]]);
| ^
Main.cpp:43:35: warning: array subscript has type 'char' [-Wchar-subscripts]
43 | c.push_back(mer[a[i]][b[i]]);
| ^
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:73:25: warning: array subscript has type 'char' [-Wchar-subscripts]
73 | seg[u] = ch[t[l]] * pw[l] % mod;
| ^
Main.cpp: In function 'int main()':
Main.cpp:111:43: warning: array subscript has type 'char' [-Wchar-subscripts]
111 | upd(1, 0, n - 1, l - 1, r - 1, ch[c]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
2296 KB |
Output is correct |
2 |
Correct |
73 ms |
2416 KB |
Output is correct |
3 |
Correct |
63 ms |
2264 KB |
Output is correct |
4 |
Correct |
56 ms |
2356 KB |
Output is correct |
5 |
Correct |
55 ms |
2288 KB |
Output is correct |
6 |
Correct |
73 ms |
2304 KB |
Output is correct |
7 |
Correct |
62 ms |
2388 KB |
Output is correct |
8 |
Correct |
59 ms |
2392 KB |
Output is correct |
9 |
Correct |
65 ms |
2392 KB |
Output is correct |
10 |
Correct |
68 ms |
2396 KB |
Output is correct |
11 |
Correct |
62 ms |
2372 KB |
Output is correct |
12 |
Correct |
60 ms |
2480 KB |
Output is correct |
13 |
Correct |
79 ms |
2372 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
66 ms |
2372 KB |
Output is correct |
16 |
Correct |
59 ms |
2648 KB |
Output is correct |
17 |
Correct |
63 ms |
2440 KB |
Output is correct |
18 |
Correct |
63 ms |
2300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
2296 KB |
Output is correct |
2 |
Correct |
73 ms |
2416 KB |
Output is correct |
3 |
Correct |
63 ms |
2264 KB |
Output is correct |
4 |
Correct |
56 ms |
2356 KB |
Output is correct |
5 |
Correct |
55 ms |
2288 KB |
Output is correct |
6 |
Correct |
73 ms |
2304 KB |
Output is correct |
7 |
Correct |
62 ms |
2388 KB |
Output is correct |
8 |
Correct |
59 ms |
2392 KB |
Output is correct |
9 |
Correct |
65 ms |
2392 KB |
Output is correct |
10 |
Correct |
68 ms |
2396 KB |
Output is correct |
11 |
Correct |
62 ms |
2372 KB |
Output is correct |
12 |
Correct |
60 ms |
2480 KB |
Output is correct |
13 |
Correct |
79 ms |
2372 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
66 ms |
2372 KB |
Output is correct |
16 |
Correct |
59 ms |
2648 KB |
Output is correct |
17 |
Correct |
63 ms |
2440 KB |
Output is correct |
18 |
Correct |
63 ms |
2300 KB |
Output is correct |
19 |
Correct |
313 ms |
15256 KB |
Output is correct |
20 |
Correct |
219 ms |
13584 KB |
Output is correct |
21 |
Correct |
209 ms |
14548 KB |
Output is correct |
22 |
Correct |
153 ms |
13948 KB |
Output is correct |
23 |
Correct |
109 ms |
3912 KB |
Output is correct |
24 |
Correct |
97 ms |
4036 KB |
Output is correct |
25 |
Correct |
161 ms |
15080 KB |
Output is correct |
26 |
Correct |
160 ms |
15172 KB |
Output is correct |
27 |
Correct |
222 ms |
15140 KB |
Output is correct |
28 |
Correct |
180 ms |
15132 KB |
Output is correct |
29 |
Correct |
183 ms |
14864 KB |
Output is correct |
30 |
Correct |
111 ms |
4000 KB |
Output is correct |
31 |
Correct |
202 ms |
15140 KB |
Output is correct |
32 |
Correct |
182 ms |
14552 KB |
Output is correct |
33 |
Correct |
100 ms |
3908 KB |
Output is correct |
34 |
Correct |
257 ms |
15148 KB |
Output is correct |
35 |
Correct |
143 ms |
13520 KB |
Output is correct |
36 |
Correct |
104 ms |
3920 KB |
Output is correct |
37 |
Correct |
91 ms |
3872 KB |
Output is correct |
38 |
Correct |
221 ms |
12880 KB |
Output is correct |
39 |
Correct |
121 ms |
12384 KB |
Output is correct |
40 |
Correct |
158 ms |
9792 KB |
Output is correct |
41 |
Correct |
308 ms |
14612 KB |
Output is correct |
42 |
Correct |
61 ms |
12584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
2296 KB |
Output is correct |
2 |
Correct |
73 ms |
2416 KB |
Output is correct |
3 |
Correct |
63 ms |
2264 KB |
Output is correct |
4 |
Correct |
56 ms |
2356 KB |
Output is correct |
5 |
Correct |
55 ms |
2288 KB |
Output is correct |
6 |
Correct |
73 ms |
2304 KB |
Output is correct |
7 |
Correct |
62 ms |
2388 KB |
Output is correct |
8 |
Correct |
59 ms |
2392 KB |
Output is correct |
9 |
Correct |
65 ms |
2392 KB |
Output is correct |
10 |
Correct |
68 ms |
2396 KB |
Output is correct |
11 |
Correct |
62 ms |
2372 KB |
Output is correct |
12 |
Correct |
60 ms |
2480 KB |
Output is correct |
13 |
Correct |
79 ms |
2372 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
66 ms |
2372 KB |
Output is correct |
16 |
Correct |
59 ms |
2648 KB |
Output is correct |
17 |
Correct |
63 ms |
2440 KB |
Output is correct |
18 |
Correct |
63 ms |
2300 KB |
Output is correct |
19 |
Correct |
73 ms |
2320 KB |
Output is correct |
20 |
Correct |
76 ms |
2340 KB |
Output is correct |
21 |
Correct |
63 ms |
2380 KB |
Output is correct |
22 |
Correct |
59 ms |
2204 KB |
Output is correct |
23 |
Correct |
84 ms |
2444 KB |
Output is correct |
24 |
Correct |
67 ms |
2368 KB |
Output is correct |
25 |
Correct |
64 ms |
2552 KB |
Output is correct |
26 |
Correct |
62 ms |
2344 KB |
Output is correct |
27 |
Correct |
66 ms |
2412 KB |
Output is correct |
28 |
Correct |
55 ms |
2236 KB |
Output is correct |
29 |
Correct |
63 ms |
2436 KB |
Output is correct |
30 |
Correct |
54 ms |
2300 KB |
Output is correct |
31 |
Correct |
72 ms |
2396 KB |
Output is correct |
32 |
Correct |
66 ms |
2456 KB |
Output is correct |
33 |
Correct |
71 ms |
2432 KB |
Output is correct |
34 |
Correct |
60 ms |
2300 KB |
Output is correct |
35 |
Correct |
67 ms |
2436 KB |
Output is correct |
36 |
Correct |
75 ms |
2392 KB |
Output is correct |
37 |
Correct |
66 ms |
2432 KB |
Output is correct |
38 |
Correct |
63 ms |
2384 KB |
Output is correct |
39 |
Correct |
68 ms |
2436 KB |
Output is correct |
40 |
Correct |
73 ms |
2380 KB |
Output is correct |
41 |
Correct |
72 ms |
2448 KB |
Output is correct |
42 |
Correct |
67 ms |
2372 KB |
Output is correct |
43 |
Correct |
64 ms |
2396 KB |
Output is correct |
44 |
Correct |
84 ms |
2412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
2296 KB |
Output is correct |
2 |
Correct |
73 ms |
2416 KB |
Output is correct |
3 |
Correct |
63 ms |
2264 KB |
Output is correct |
4 |
Correct |
56 ms |
2356 KB |
Output is correct |
5 |
Correct |
55 ms |
2288 KB |
Output is correct |
6 |
Correct |
73 ms |
2304 KB |
Output is correct |
7 |
Correct |
62 ms |
2388 KB |
Output is correct |
8 |
Correct |
59 ms |
2392 KB |
Output is correct |
9 |
Correct |
65 ms |
2392 KB |
Output is correct |
10 |
Correct |
68 ms |
2396 KB |
Output is correct |
11 |
Correct |
62 ms |
2372 KB |
Output is correct |
12 |
Correct |
60 ms |
2480 KB |
Output is correct |
13 |
Correct |
79 ms |
2372 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
66 ms |
2372 KB |
Output is correct |
16 |
Correct |
59 ms |
2648 KB |
Output is correct |
17 |
Correct |
63 ms |
2440 KB |
Output is correct |
18 |
Correct |
63 ms |
2300 KB |
Output is correct |
19 |
Correct |
313 ms |
15256 KB |
Output is correct |
20 |
Correct |
219 ms |
13584 KB |
Output is correct |
21 |
Correct |
209 ms |
14548 KB |
Output is correct |
22 |
Correct |
153 ms |
13948 KB |
Output is correct |
23 |
Correct |
109 ms |
3912 KB |
Output is correct |
24 |
Correct |
97 ms |
4036 KB |
Output is correct |
25 |
Correct |
161 ms |
15080 KB |
Output is correct |
26 |
Correct |
160 ms |
15172 KB |
Output is correct |
27 |
Correct |
222 ms |
15140 KB |
Output is correct |
28 |
Correct |
180 ms |
15132 KB |
Output is correct |
29 |
Correct |
183 ms |
14864 KB |
Output is correct |
30 |
Correct |
111 ms |
4000 KB |
Output is correct |
31 |
Correct |
202 ms |
15140 KB |
Output is correct |
32 |
Correct |
182 ms |
14552 KB |
Output is correct |
33 |
Correct |
100 ms |
3908 KB |
Output is correct |
34 |
Correct |
257 ms |
15148 KB |
Output is correct |
35 |
Correct |
143 ms |
13520 KB |
Output is correct |
36 |
Correct |
104 ms |
3920 KB |
Output is correct |
37 |
Correct |
91 ms |
3872 KB |
Output is correct |
38 |
Correct |
221 ms |
12880 KB |
Output is correct |
39 |
Correct |
121 ms |
12384 KB |
Output is correct |
40 |
Correct |
158 ms |
9792 KB |
Output is correct |
41 |
Correct |
308 ms |
14612 KB |
Output is correct |
42 |
Correct |
61 ms |
12584 KB |
Output is correct |
43 |
Correct |
73 ms |
2320 KB |
Output is correct |
44 |
Correct |
76 ms |
2340 KB |
Output is correct |
45 |
Correct |
63 ms |
2380 KB |
Output is correct |
46 |
Correct |
59 ms |
2204 KB |
Output is correct |
47 |
Correct |
84 ms |
2444 KB |
Output is correct |
48 |
Correct |
67 ms |
2368 KB |
Output is correct |
49 |
Correct |
64 ms |
2552 KB |
Output is correct |
50 |
Correct |
62 ms |
2344 KB |
Output is correct |
51 |
Correct |
66 ms |
2412 KB |
Output is correct |
52 |
Correct |
55 ms |
2236 KB |
Output is correct |
53 |
Correct |
63 ms |
2436 KB |
Output is correct |
54 |
Correct |
54 ms |
2300 KB |
Output is correct |
55 |
Correct |
72 ms |
2396 KB |
Output is correct |
56 |
Correct |
66 ms |
2456 KB |
Output is correct |
57 |
Correct |
71 ms |
2432 KB |
Output is correct |
58 |
Correct |
60 ms |
2300 KB |
Output is correct |
59 |
Correct |
67 ms |
2436 KB |
Output is correct |
60 |
Correct |
75 ms |
2392 KB |
Output is correct |
61 |
Correct |
66 ms |
2432 KB |
Output is correct |
62 |
Correct |
63 ms |
2384 KB |
Output is correct |
63 |
Correct |
68 ms |
2436 KB |
Output is correct |
64 |
Correct |
73 ms |
2380 KB |
Output is correct |
65 |
Correct |
72 ms |
2448 KB |
Output is correct |
66 |
Correct |
67 ms |
2372 KB |
Output is correct |
67 |
Correct |
64 ms |
2396 KB |
Output is correct |
68 |
Correct |
84 ms |
2412 KB |
Output is correct |
69 |
Correct |
259 ms |
14344 KB |
Output is correct |
70 |
Correct |
305 ms |
13928 KB |
Output is correct |
71 |
Correct |
97 ms |
3976 KB |
Output is correct |
72 |
Correct |
95 ms |
3876 KB |
Output is correct |
73 |
Correct |
95 ms |
3936 KB |
Output is correct |
74 |
Correct |
169 ms |
14472 KB |
Output is correct |
75 |
Correct |
97 ms |
3840 KB |
Output is correct |
76 |
Correct |
155 ms |
15760 KB |
Output is correct |
77 |
Correct |
155 ms |
14656 KB |
Output is correct |
78 |
Correct |
97 ms |
3912 KB |
Output is correct |
79 |
Correct |
98 ms |
3908 KB |
Output is correct |
80 |
Correct |
205 ms |
13820 KB |
Output is correct |
81 |
Correct |
102 ms |
3892 KB |
Output is correct |
82 |
Correct |
247 ms |
15584 KB |
Output is correct |
83 |
Correct |
222 ms |
15336 KB |
Output is correct |
84 |
Correct |
117 ms |
3900 KB |
Output is correct |
85 |
Correct |
109 ms |
3896 KB |
Output is correct |
86 |
Correct |
235 ms |
13992 KB |
Output is correct |
87 |
Correct |
255 ms |
15600 KB |
Output is correct |
88 |
Correct |
115 ms |
3892 KB |
Output is correct |
89 |
Correct |
236 ms |
14680 KB |
Output is correct |
90 |
Correct |
250 ms |
15528 KB |
Output is correct |
91 |
Correct |
121 ms |
4080 KB |
Output is correct |
92 |
Correct |
186 ms |
13916 KB |
Output is correct |
93 |
Correct |
118 ms |
4000 KB |
Output is correct |
94 |
Correct |
101 ms |
3896 KB |
Output is correct |
95 |
Correct |
100 ms |
3892 KB |
Output is correct |
96 |
Correct |
227 ms |
14008 KB |
Output is correct |
97 |
Correct |
182 ms |
13612 KB |
Output is correct |
98 |
Correct |
176 ms |
10904 KB |
Output is correct |
99 |
Correct |
342 ms |
15804 KB |
Output is correct |
100 |
Correct |
131 ms |
12932 KB |
Output is correct |