#include <bits/stdc++.h>
#define fastio ios_base :: sync_with_stdio(0), cin.tie(0);
using namespace std;
using ll = long long;
const int mxN = 2e5 + 5, mod = 1e9 + 7, p = 31;
int n, h[3][mxN];
string s[3];
int t[mxN * 4];
char Mod[mxN * 4];
string A;
int binpow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = ans * 1ll * a % mod;
a = a * 1ll * a % mod;
b >>= 1;
}
return ans;
}
void Build(int v = 1, int tl = 1, int tr = n) {
Mod[v] = '#';
if (tl == tr) {
t[v] = A[tl - 1];
return;
}
int tm = (tl + tr) / 2;
Build(v * 2, tl, tm);
Build(v * 2 + 1, tm + 1, tr);
int sz = tr - tm;
t[v] = (t[v * 2] * 1ll * binpow(p, sz) % mod + t[v * 2 + 1]) % mod;
}
void Push(int v, int tl, int tr) {
if (Mod[v] != '#') {
int i = 0;
if (Mod[v] == 'O')
i = 1;
else if (Mod[v] == 'I')
i = 2;
t[v] = h[i][tr - tl + 1];
if (tl != tr)
Mod[v * 2] = Mod[v * 2 + 1] = Mod[v];
Mod[v] = '#';
}
}
void Upd(int l, int r, char c, int v = 1, int tl = 1, int tr = n) {
Push(v, tl, tr);
if (l > tr || r < tl)
return;
if (l <= tl && tr <= r) {
Mod[v] = c;
Push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
Upd(l, r, c, v * 2, tl, tm);
Upd(l, r, c, v * 2 + 1, tm + 1, tr);
int sz = tr - tm;
t[v] = (t[v * 2] * 1ll * binpow(p, sz) % mod + t[v * 2 + 1]) % mod;
}
pair <int, int> Get(int l, int r, int v = 1, int tl = 1, int tr = n) {
Push(v, tl, tr);
if (l > tr || r < tl)
return {0, 0};
if (l <= tl && tr <= r)
return {t[v], tr - tl + 1};
int tm = (tl + tr) / 2;
auto at = Get(l, r, v * 2, tl, tm);
int left = at.first, szz = at.second;
at = Get(l, r, v * 2 + 1, tm + 1, tr);
int right = at.first, sz = at.second;
return {(left * 1ll * binpow(p, sz) % mod + right) % mod, szz + sz};
}
int calc(string st) {
int ans = 0;
for (int i = 0; i < st.size(); ++i)
ans = (ans * 1ll * p % mod + st[i]) % mod;
return ans;
}
string merge(string a, string b) {
string ret;
char sy[3] = {'J', 'O', 'I'};
for (int i = 0; i < a.size(); ++i) {
if (a[i] == b[i])
ret += a[i];
else {
for (int j = 0; j < 3; ++j) {
if (sy[j] != a[i] && sy[j] != b[i])
ret += sy[j];
}
}
}
return ret;
}
int main() {
fastio;
cin >> n >> s[0] >> s[1] >> s[2];
for (int i = 1; i <= n; ++i) {
h[0][i] = (h[0][i - 1] * 1ll * p % mod + 'J') % mod;
h[1][i] = (h[1][i - 1] * 1ll * p % mod + 'O') % mod;
h[2][i] = (h[2][i - 1] * 1ll * p % mod + 'I') % mod;
}
set <int> st1;
set <string> st2;
for (int i = 0; i < 3; ++i) {
st1.insert(calc(s[i]));
st2.insert(s[i]);
}
while (true) {
vector <string> v;
for (auto x : st2) {
for (auto y : st2) {
string nw = merge(x, y);
if (st2.find(nw) == st2.end())
v.push_back(nw);
}
}
if (v.empty())
break;
for (auto x : v)
st2.insert(x), st1.insert(calc(x));
}
int q;
cin >> q;
cin >> A;
Build();
if (st1.find(Get(1, n).first) != st1.end())
cout << "Yes\n";
else
cout << "No\n";
while (q--) {
int l, r;
cin >> l >> r;
char c;
cin >> c;
Upd(l, r, c);
if (st1.find(Get(1, n).first) != st1.end())
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'int calc(std::string)':
Main.cpp:86:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0; i < st.size(); ++i)
| ~~^~~~~~~~~~~
Main.cpp: In function 'std::string merge(std::string, std::string)':
Main.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i = 0; i < a.size(); ++i) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
2300 KB |
Output is correct |
2 |
Correct |
99 ms |
2412 KB |
Output is correct |
3 |
Correct |
97 ms |
2348 KB |
Output is correct |
4 |
Correct |
82 ms |
2272 KB |
Output is correct |
5 |
Correct |
81 ms |
2392 KB |
Output is correct |
6 |
Correct |
85 ms |
2256 KB |
Output is correct |
7 |
Correct |
85 ms |
2420 KB |
Output is correct |
8 |
Correct |
89 ms |
2516 KB |
Output is correct |
9 |
Correct |
93 ms |
2392 KB |
Output is correct |
10 |
Correct |
88 ms |
2456 KB |
Output is correct |
11 |
Correct |
91 ms |
2520 KB |
Output is correct |
12 |
Correct |
91 ms |
2360 KB |
Output is correct |
13 |
Correct |
87 ms |
2444 KB |
Output is correct |
14 |
Correct |
97 ms |
2372 KB |
Output is correct |
15 |
Correct |
87 ms |
2416 KB |
Output is correct |
16 |
Correct |
86 ms |
2384 KB |
Output is correct |
17 |
Correct |
86 ms |
2404 KB |
Output is correct |
18 |
Correct |
88 ms |
2372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
2300 KB |
Output is correct |
2 |
Correct |
99 ms |
2412 KB |
Output is correct |
3 |
Correct |
97 ms |
2348 KB |
Output is correct |
4 |
Correct |
82 ms |
2272 KB |
Output is correct |
5 |
Correct |
81 ms |
2392 KB |
Output is correct |
6 |
Correct |
85 ms |
2256 KB |
Output is correct |
7 |
Correct |
85 ms |
2420 KB |
Output is correct |
8 |
Correct |
89 ms |
2516 KB |
Output is correct |
9 |
Correct |
93 ms |
2392 KB |
Output is correct |
10 |
Correct |
88 ms |
2456 KB |
Output is correct |
11 |
Correct |
91 ms |
2520 KB |
Output is correct |
12 |
Correct |
91 ms |
2360 KB |
Output is correct |
13 |
Correct |
87 ms |
2444 KB |
Output is correct |
14 |
Correct |
97 ms |
2372 KB |
Output is correct |
15 |
Correct |
87 ms |
2416 KB |
Output is correct |
16 |
Correct |
86 ms |
2384 KB |
Output is correct |
17 |
Correct |
86 ms |
2404 KB |
Output is correct |
18 |
Correct |
88 ms |
2372 KB |
Output is correct |
19 |
Correct |
414 ms |
11344 KB |
Output is correct |
20 |
Correct |
473 ms |
11248 KB |
Output is correct |
21 |
Correct |
300 ms |
10644 KB |
Output is correct |
22 |
Correct |
297 ms |
10244 KB |
Output is correct |
23 |
Correct |
187 ms |
3652 KB |
Output is correct |
24 |
Correct |
201 ms |
3896 KB |
Output is correct |
25 |
Correct |
296 ms |
11244 KB |
Output is correct |
26 |
Correct |
320 ms |
11324 KB |
Output is correct |
27 |
Correct |
359 ms |
11236 KB |
Output is correct |
28 |
Correct |
336 ms |
11216 KB |
Output is correct |
29 |
Correct |
349 ms |
10584 KB |
Output is correct |
30 |
Correct |
216 ms |
3632 KB |
Output is correct |
31 |
Correct |
337 ms |
11292 KB |
Output is correct |
32 |
Correct |
317 ms |
10616 KB |
Output is correct |
33 |
Correct |
192 ms |
3664 KB |
Output is correct |
34 |
Correct |
331 ms |
11324 KB |
Output is correct |
35 |
Correct |
281 ms |
9752 KB |
Output is correct |
36 |
Correct |
203 ms |
3572 KB |
Output is correct |
37 |
Correct |
188 ms |
3568 KB |
Output is correct |
38 |
Correct |
393 ms |
11192 KB |
Output is correct |
39 |
Correct |
286 ms |
11300 KB |
Output is correct |
40 |
Correct |
264 ms |
8008 KB |
Output is correct |
41 |
Correct |
468 ms |
11496 KB |
Output is correct |
42 |
Correct |
51 ms |
10792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
2300 KB |
Output is correct |
2 |
Correct |
99 ms |
2412 KB |
Output is correct |
3 |
Correct |
97 ms |
2348 KB |
Output is correct |
4 |
Correct |
82 ms |
2272 KB |
Output is correct |
5 |
Correct |
81 ms |
2392 KB |
Output is correct |
6 |
Correct |
85 ms |
2256 KB |
Output is correct |
7 |
Correct |
85 ms |
2420 KB |
Output is correct |
8 |
Correct |
89 ms |
2516 KB |
Output is correct |
9 |
Correct |
93 ms |
2392 KB |
Output is correct |
10 |
Correct |
88 ms |
2456 KB |
Output is correct |
11 |
Correct |
91 ms |
2520 KB |
Output is correct |
12 |
Correct |
91 ms |
2360 KB |
Output is correct |
13 |
Correct |
87 ms |
2444 KB |
Output is correct |
14 |
Correct |
97 ms |
2372 KB |
Output is correct |
15 |
Correct |
87 ms |
2416 KB |
Output is correct |
16 |
Correct |
86 ms |
2384 KB |
Output is correct |
17 |
Correct |
86 ms |
2404 KB |
Output is correct |
18 |
Correct |
88 ms |
2372 KB |
Output is correct |
19 |
Correct |
101 ms |
2372 KB |
Output is correct |
20 |
Correct |
102 ms |
2248 KB |
Output is correct |
21 |
Correct |
87 ms |
2416 KB |
Output is correct |
22 |
Correct |
92 ms |
2228 KB |
Output is correct |
23 |
Correct |
89 ms |
2424 KB |
Output is correct |
24 |
Correct |
82 ms |
2384 KB |
Output is correct |
25 |
Correct |
88 ms |
2372 KB |
Output is correct |
26 |
Correct |
79 ms |
2372 KB |
Output is correct |
27 |
Correct |
85 ms |
2372 KB |
Output is correct |
28 |
Correct |
77 ms |
2176 KB |
Output is correct |
29 |
Correct |
87 ms |
2436 KB |
Output is correct |
30 |
Correct |
75 ms |
2244 KB |
Output is correct |
31 |
Correct |
87 ms |
2484 KB |
Output is correct |
32 |
Correct |
90 ms |
2372 KB |
Output is correct |
33 |
Correct |
87 ms |
2380 KB |
Output is correct |
34 |
Correct |
78 ms |
2324 KB |
Output is correct |
35 |
Correct |
89 ms |
2456 KB |
Output is correct |
36 |
Correct |
94 ms |
2488 KB |
Output is correct |
37 |
Correct |
87 ms |
2440 KB |
Output is correct |
38 |
Correct |
96 ms |
2372 KB |
Output is correct |
39 |
Correct |
96 ms |
2428 KB |
Output is correct |
40 |
Correct |
92 ms |
2424 KB |
Output is correct |
41 |
Correct |
92 ms |
2404 KB |
Output is correct |
42 |
Correct |
88 ms |
2384 KB |
Output is correct |
43 |
Correct |
103 ms |
2368 KB |
Output is correct |
44 |
Correct |
92 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
2300 KB |
Output is correct |
2 |
Correct |
99 ms |
2412 KB |
Output is correct |
3 |
Correct |
97 ms |
2348 KB |
Output is correct |
4 |
Correct |
82 ms |
2272 KB |
Output is correct |
5 |
Correct |
81 ms |
2392 KB |
Output is correct |
6 |
Correct |
85 ms |
2256 KB |
Output is correct |
7 |
Correct |
85 ms |
2420 KB |
Output is correct |
8 |
Correct |
89 ms |
2516 KB |
Output is correct |
9 |
Correct |
93 ms |
2392 KB |
Output is correct |
10 |
Correct |
88 ms |
2456 KB |
Output is correct |
11 |
Correct |
91 ms |
2520 KB |
Output is correct |
12 |
Correct |
91 ms |
2360 KB |
Output is correct |
13 |
Correct |
87 ms |
2444 KB |
Output is correct |
14 |
Correct |
97 ms |
2372 KB |
Output is correct |
15 |
Correct |
87 ms |
2416 KB |
Output is correct |
16 |
Correct |
86 ms |
2384 KB |
Output is correct |
17 |
Correct |
86 ms |
2404 KB |
Output is correct |
18 |
Correct |
88 ms |
2372 KB |
Output is correct |
19 |
Correct |
414 ms |
11344 KB |
Output is correct |
20 |
Correct |
473 ms |
11248 KB |
Output is correct |
21 |
Correct |
300 ms |
10644 KB |
Output is correct |
22 |
Correct |
297 ms |
10244 KB |
Output is correct |
23 |
Correct |
187 ms |
3652 KB |
Output is correct |
24 |
Correct |
201 ms |
3896 KB |
Output is correct |
25 |
Correct |
296 ms |
11244 KB |
Output is correct |
26 |
Correct |
320 ms |
11324 KB |
Output is correct |
27 |
Correct |
359 ms |
11236 KB |
Output is correct |
28 |
Correct |
336 ms |
11216 KB |
Output is correct |
29 |
Correct |
349 ms |
10584 KB |
Output is correct |
30 |
Correct |
216 ms |
3632 KB |
Output is correct |
31 |
Correct |
337 ms |
11292 KB |
Output is correct |
32 |
Correct |
317 ms |
10616 KB |
Output is correct |
33 |
Correct |
192 ms |
3664 KB |
Output is correct |
34 |
Correct |
331 ms |
11324 KB |
Output is correct |
35 |
Correct |
281 ms |
9752 KB |
Output is correct |
36 |
Correct |
203 ms |
3572 KB |
Output is correct |
37 |
Correct |
188 ms |
3568 KB |
Output is correct |
38 |
Correct |
393 ms |
11192 KB |
Output is correct |
39 |
Correct |
286 ms |
11300 KB |
Output is correct |
40 |
Correct |
264 ms |
8008 KB |
Output is correct |
41 |
Correct |
468 ms |
11496 KB |
Output is correct |
42 |
Correct |
51 ms |
10792 KB |
Output is correct |
43 |
Correct |
101 ms |
2372 KB |
Output is correct |
44 |
Correct |
102 ms |
2248 KB |
Output is correct |
45 |
Correct |
87 ms |
2416 KB |
Output is correct |
46 |
Correct |
92 ms |
2228 KB |
Output is correct |
47 |
Correct |
89 ms |
2424 KB |
Output is correct |
48 |
Correct |
82 ms |
2384 KB |
Output is correct |
49 |
Correct |
88 ms |
2372 KB |
Output is correct |
50 |
Correct |
79 ms |
2372 KB |
Output is correct |
51 |
Correct |
85 ms |
2372 KB |
Output is correct |
52 |
Correct |
77 ms |
2176 KB |
Output is correct |
53 |
Correct |
87 ms |
2436 KB |
Output is correct |
54 |
Correct |
75 ms |
2244 KB |
Output is correct |
55 |
Correct |
87 ms |
2484 KB |
Output is correct |
56 |
Correct |
90 ms |
2372 KB |
Output is correct |
57 |
Correct |
87 ms |
2380 KB |
Output is correct |
58 |
Correct |
78 ms |
2324 KB |
Output is correct |
59 |
Correct |
89 ms |
2456 KB |
Output is correct |
60 |
Correct |
94 ms |
2488 KB |
Output is correct |
61 |
Correct |
87 ms |
2440 KB |
Output is correct |
62 |
Correct |
96 ms |
2372 KB |
Output is correct |
63 |
Correct |
96 ms |
2428 KB |
Output is correct |
64 |
Correct |
92 ms |
2424 KB |
Output is correct |
65 |
Correct |
92 ms |
2404 KB |
Output is correct |
66 |
Correct |
88 ms |
2384 KB |
Output is correct |
67 |
Correct |
103 ms |
2368 KB |
Output is correct |
68 |
Correct |
92 ms |
2424 KB |
Output is correct |
69 |
Correct |
762 ms |
13108 KB |
Output is correct |
70 |
Correct |
949 ms |
14984 KB |
Output is correct |
71 |
Correct |
192 ms |
3696 KB |
Output is correct |
72 |
Correct |
254 ms |
3816 KB |
Output is correct |
73 |
Correct |
204 ms |
3716 KB |
Output is correct |
74 |
Correct |
291 ms |
10272 KB |
Output is correct |
75 |
Correct |
201 ms |
3696 KB |
Output is correct |
76 |
Correct |
358 ms |
11100 KB |
Output is correct |
77 |
Correct |
313 ms |
10380 KB |
Output is correct |
78 |
Correct |
192 ms |
3652 KB |
Output is correct |
79 |
Correct |
188 ms |
3640 KB |
Output is correct |
80 |
Correct |
619 ms |
12028 KB |
Output is correct |
81 |
Correct |
233 ms |
3932 KB |
Output is correct |
82 |
Correct |
786 ms |
15080 KB |
Output is correct |
83 |
Correct |
744 ms |
14332 KB |
Output is correct |
84 |
Correct |
225 ms |
3776 KB |
Output is correct |
85 |
Correct |
225 ms |
3824 KB |
Output is correct |
86 |
Correct |
495 ms |
12648 KB |
Output is correct |
87 |
Correct |
599 ms |
14964 KB |
Output is correct |
88 |
Correct |
231 ms |
3816 KB |
Output is correct |
89 |
Correct |
542 ms |
13576 KB |
Output is correct |
90 |
Correct |
573 ms |
15056 KB |
Output is correct |
91 |
Correct |
249 ms |
3792 KB |
Output is correct |
92 |
Correct |
629 ms |
12428 KB |
Output is correct |
93 |
Correct |
223 ms |
3820 KB |
Output is correct |
94 |
Correct |
259 ms |
3808 KB |
Output is correct |
95 |
Correct |
220 ms |
3932 KB |
Output is correct |
96 |
Correct |
392 ms |
11116 KB |
Output is correct |
97 |
Correct |
480 ms |
15168 KB |
Output is correct |
98 |
Correct |
551 ms |
10600 KB |
Output is correct |
99 |
Correct |
945 ms |
15176 KB |
Output is correct |
100 |
Correct |
503 ms |
14408 KB |
Output is correct |