#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define endl '\n'
#define dbg(x) cerr << #x << " = " << x << endl;
typedef vector<int> vi;
typedef vector<string> vs;
const int base = 9970003, mod = 1e9 + 7, N = 2e5 + 5;
int n, q, p[N], psum[N], st[N * 4], rset[N * 4];
string a[3], t;
set<int> se;
string joi = "#JOI";
int hash_c(char c) {
if (c == 'J') return 1;
else if (c == 'O') return 2;
else return 3;
}
int hash_s(string s) {
int ret = 0;
for (int i = 0; i < int(s.size()); i++) (ret += p[i] * hash_c(s[i]) % mod) %= mod;
return ret;
}
void pull(int v, int l, int r) {
int m = (l + r) / 2;
st[v] = (st[2 * v] + st[2 * v + 1] * p[m - l + 1] % mod) % mod;
}
void push(int v, int l, int r) {
if (rset[v] == 0) return;
int m = (l + r) / 2;
rset[2 * v + 1] = rset[2 * v] = rset[v];
st[2*v] = rset[v] * psum[m - l + 1] % mod;
st[2*v+1] = rset[v] * psum[r - m] % mod;
rset[v] = 0;
}
void build(int v = 1, int l = 0, int r = n - 1) {
if (l == r) {
st[v] = hash_c(t[l]);
} else {
int m = (l + r) / 2;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
pull(v, l, r);
}
}
void upd(int ql, int qr, int x, int v = 1, int l = 0, int r = n - 1) {
// push(v, l, r);
if (qr < l or ql > r) return;
if (l >= ql and r <= qr) {
rset[v] = x;
st[v] = rset[v] * psum[r - l + 1] % mod;
//push(v, l, r);
return;
}
push(v, l, r);
int m = (l + r) / 2;
upd(ql, qr, x, v * 2, l, m);
upd(ql, qr, x, v * 2 + 1, m + 1, r);
pull(v, l, r);
}
void comb(vs a) {
string s = a[0];
for (int i = 1; i < int(a.size()); i++) {
string ns = "";
for (int j = 0; j < n; j++) {
if (s[j] == a[i][j]) ns += s[j];
else ns += joi[(6 - hash_c(s[j]) - hash_c(a[i][j]))];
}
s = ns;
}
se.insert(hash_s(s));
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i - 1] * base % mod;
for (int i = 1; i < N; i++) psum[i] = (psum[i - 1] + p[i - 1]) % mod;
cin >> n >> a[0] >> a[1] >> a[2] >> q >> t;
build();
comb({a[0]}); comb({a[1]}); comb({a[2]}); comb({a[0], a[1]}); comb({a[0], a[2]}); comb({a[1], a[2]});
comb({a[0], a[1], a[2]}); comb({a[0], a[2], a[1]}); comb({a[1], a[2], a[0]});
if (se.count(st[1])) cout << "Yes" << endl;
else cout << "No" << endl;
while (q--) {
int l, r; char c; cin >> l >> r >> c; int o = hash_c(c); l--; r--;
upd(l, r, o);
if (se.count(st[1])) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7248 KB |
Output is correct |
2 |
Correct |
65 ms |
7048 KB |
Output is correct |
3 |
Correct |
64 ms |
7172 KB |
Output is correct |
4 |
Correct |
65 ms |
7248 KB |
Output is correct |
5 |
Correct |
54 ms |
7160 KB |
Output is correct |
6 |
Correct |
56 ms |
7504 KB |
Output is correct |
7 |
Correct |
56 ms |
7252 KB |
Output is correct |
8 |
Correct |
59 ms |
7240 KB |
Output is correct |
9 |
Correct |
66 ms |
7252 KB |
Output is correct |
10 |
Correct |
59 ms |
7252 KB |
Output is correct |
11 |
Correct |
60 ms |
7252 KB |
Output is correct |
12 |
Correct |
70 ms |
7248 KB |
Output is correct |
13 |
Correct |
59 ms |
7252 KB |
Output is correct |
14 |
Correct |
60 ms |
7264 KB |
Output is correct |
15 |
Correct |
61 ms |
7252 KB |
Output is correct |
16 |
Correct |
58 ms |
7248 KB |
Output is correct |
17 |
Correct |
59 ms |
7244 KB |
Output is correct |
18 |
Correct |
72 ms |
7108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7248 KB |
Output is correct |
2 |
Correct |
65 ms |
7048 KB |
Output is correct |
3 |
Correct |
64 ms |
7172 KB |
Output is correct |
4 |
Correct |
65 ms |
7248 KB |
Output is correct |
5 |
Correct |
54 ms |
7160 KB |
Output is correct |
6 |
Correct |
56 ms |
7504 KB |
Output is correct |
7 |
Correct |
56 ms |
7252 KB |
Output is correct |
8 |
Correct |
59 ms |
7240 KB |
Output is correct |
9 |
Correct |
66 ms |
7252 KB |
Output is correct |
10 |
Correct |
59 ms |
7252 KB |
Output is correct |
11 |
Correct |
60 ms |
7252 KB |
Output is correct |
12 |
Correct |
70 ms |
7248 KB |
Output is correct |
13 |
Correct |
59 ms |
7252 KB |
Output is correct |
14 |
Correct |
60 ms |
7264 KB |
Output is correct |
15 |
Correct |
61 ms |
7252 KB |
Output is correct |
16 |
Correct |
58 ms |
7248 KB |
Output is correct |
17 |
Correct |
59 ms |
7244 KB |
Output is correct |
18 |
Correct |
72 ms |
7108 KB |
Output is correct |
19 |
Correct |
183 ms |
18532 KB |
Output is correct |
20 |
Correct |
187 ms |
16756 KB |
Output is correct |
21 |
Correct |
133 ms |
18840 KB |
Output is correct |
22 |
Correct |
128 ms |
17832 KB |
Output is correct |
23 |
Correct |
92 ms |
12264 KB |
Output is correct |
24 |
Correct |
96 ms |
12116 KB |
Output is correct |
25 |
Correct |
134 ms |
18480 KB |
Output is correct |
26 |
Correct |
153 ms |
18468 KB |
Output is correct |
27 |
Correct |
152 ms |
18512 KB |
Output is correct |
28 |
Correct |
151 ms |
18548 KB |
Output is correct |
29 |
Correct |
146 ms |
18368 KB |
Output is correct |
30 |
Correct |
104 ms |
12116 KB |
Output is correct |
31 |
Correct |
152 ms |
18504 KB |
Output is correct |
32 |
Correct |
142 ms |
18408 KB |
Output is correct |
33 |
Correct |
114 ms |
11976 KB |
Output is correct |
34 |
Correct |
153 ms |
18544 KB |
Output is correct |
35 |
Correct |
121 ms |
17852 KB |
Output is correct |
36 |
Correct |
95 ms |
12196 KB |
Output is correct |
37 |
Correct |
91 ms |
12112 KB |
Output is correct |
38 |
Correct |
168 ms |
18452 KB |
Output is correct |
39 |
Correct |
124 ms |
16300 KB |
Output is correct |
40 |
Correct |
135 ms |
13616 KB |
Output is correct |
41 |
Correct |
214 ms |
18800 KB |
Output is correct |
42 |
Correct |
50 ms |
14096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7248 KB |
Output is correct |
2 |
Correct |
65 ms |
7048 KB |
Output is correct |
3 |
Correct |
64 ms |
7172 KB |
Output is correct |
4 |
Correct |
65 ms |
7248 KB |
Output is correct |
5 |
Correct |
54 ms |
7160 KB |
Output is correct |
6 |
Correct |
56 ms |
7504 KB |
Output is correct |
7 |
Correct |
56 ms |
7252 KB |
Output is correct |
8 |
Correct |
59 ms |
7240 KB |
Output is correct |
9 |
Correct |
66 ms |
7252 KB |
Output is correct |
10 |
Correct |
59 ms |
7252 KB |
Output is correct |
11 |
Correct |
60 ms |
7252 KB |
Output is correct |
12 |
Correct |
70 ms |
7248 KB |
Output is correct |
13 |
Correct |
59 ms |
7252 KB |
Output is correct |
14 |
Correct |
60 ms |
7264 KB |
Output is correct |
15 |
Correct |
61 ms |
7252 KB |
Output is correct |
16 |
Correct |
58 ms |
7248 KB |
Output is correct |
17 |
Correct |
59 ms |
7244 KB |
Output is correct |
18 |
Correct |
72 ms |
7108 KB |
Output is correct |
19 |
Correct |
65 ms |
7252 KB |
Output is correct |
20 |
Correct |
68 ms |
7248 KB |
Output is correct |
21 |
Correct |
72 ms |
7248 KB |
Output is correct |
22 |
Correct |
54 ms |
7100 KB |
Output is correct |
23 |
Correct |
60 ms |
7200 KB |
Output is correct |
24 |
Correct |
61 ms |
7240 KB |
Output is correct |
25 |
Correct |
62 ms |
7192 KB |
Output is correct |
26 |
Correct |
59 ms |
7248 KB |
Output is correct |
27 |
Correct |
60 ms |
7248 KB |
Output is correct |
28 |
Correct |
53 ms |
6996 KB |
Output is correct |
29 |
Correct |
59 ms |
7212 KB |
Output is correct |
30 |
Correct |
54 ms |
7252 KB |
Output is correct |
31 |
Correct |
61 ms |
7096 KB |
Output is correct |
32 |
Correct |
60 ms |
7248 KB |
Output is correct |
33 |
Correct |
62 ms |
7168 KB |
Output is correct |
34 |
Correct |
57 ms |
7508 KB |
Output is correct |
35 |
Correct |
61 ms |
7252 KB |
Output is correct |
36 |
Correct |
62 ms |
7092 KB |
Output is correct |
37 |
Correct |
61 ms |
7252 KB |
Output is correct |
38 |
Correct |
62 ms |
7236 KB |
Output is correct |
39 |
Correct |
61 ms |
7248 KB |
Output is correct |
40 |
Correct |
62 ms |
7228 KB |
Output is correct |
41 |
Correct |
61 ms |
7248 KB |
Output is correct |
42 |
Correct |
65 ms |
7096 KB |
Output is correct |
43 |
Correct |
58 ms |
7248 KB |
Output is correct |
44 |
Correct |
67 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7248 KB |
Output is correct |
2 |
Correct |
65 ms |
7048 KB |
Output is correct |
3 |
Correct |
64 ms |
7172 KB |
Output is correct |
4 |
Correct |
65 ms |
7248 KB |
Output is correct |
5 |
Correct |
54 ms |
7160 KB |
Output is correct |
6 |
Correct |
56 ms |
7504 KB |
Output is correct |
7 |
Correct |
56 ms |
7252 KB |
Output is correct |
8 |
Correct |
59 ms |
7240 KB |
Output is correct |
9 |
Correct |
66 ms |
7252 KB |
Output is correct |
10 |
Correct |
59 ms |
7252 KB |
Output is correct |
11 |
Correct |
60 ms |
7252 KB |
Output is correct |
12 |
Correct |
70 ms |
7248 KB |
Output is correct |
13 |
Correct |
59 ms |
7252 KB |
Output is correct |
14 |
Correct |
60 ms |
7264 KB |
Output is correct |
15 |
Correct |
61 ms |
7252 KB |
Output is correct |
16 |
Correct |
58 ms |
7248 KB |
Output is correct |
17 |
Correct |
59 ms |
7244 KB |
Output is correct |
18 |
Correct |
72 ms |
7108 KB |
Output is correct |
19 |
Correct |
183 ms |
18532 KB |
Output is correct |
20 |
Correct |
187 ms |
16756 KB |
Output is correct |
21 |
Correct |
133 ms |
18840 KB |
Output is correct |
22 |
Correct |
128 ms |
17832 KB |
Output is correct |
23 |
Correct |
92 ms |
12264 KB |
Output is correct |
24 |
Correct |
96 ms |
12116 KB |
Output is correct |
25 |
Correct |
134 ms |
18480 KB |
Output is correct |
26 |
Correct |
153 ms |
18468 KB |
Output is correct |
27 |
Correct |
152 ms |
18512 KB |
Output is correct |
28 |
Correct |
151 ms |
18548 KB |
Output is correct |
29 |
Correct |
146 ms |
18368 KB |
Output is correct |
30 |
Correct |
104 ms |
12116 KB |
Output is correct |
31 |
Correct |
152 ms |
18504 KB |
Output is correct |
32 |
Correct |
142 ms |
18408 KB |
Output is correct |
33 |
Correct |
114 ms |
11976 KB |
Output is correct |
34 |
Correct |
153 ms |
18544 KB |
Output is correct |
35 |
Correct |
121 ms |
17852 KB |
Output is correct |
36 |
Correct |
95 ms |
12196 KB |
Output is correct |
37 |
Correct |
91 ms |
12112 KB |
Output is correct |
38 |
Correct |
168 ms |
18452 KB |
Output is correct |
39 |
Correct |
124 ms |
16300 KB |
Output is correct |
40 |
Correct |
135 ms |
13616 KB |
Output is correct |
41 |
Correct |
214 ms |
18800 KB |
Output is correct |
42 |
Correct |
50 ms |
14096 KB |
Output is correct |
43 |
Correct |
65 ms |
7252 KB |
Output is correct |
44 |
Correct |
68 ms |
7248 KB |
Output is correct |
45 |
Correct |
72 ms |
7248 KB |
Output is correct |
46 |
Correct |
54 ms |
7100 KB |
Output is correct |
47 |
Correct |
60 ms |
7200 KB |
Output is correct |
48 |
Correct |
61 ms |
7240 KB |
Output is correct |
49 |
Correct |
62 ms |
7192 KB |
Output is correct |
50 |
Correct |
59 ms |
7248 KB |
Output is correct |
51 |
Correct |
60 ms |
7248 KB |
Output is correct |
52 |
Correct |
53 ms |
6996 KB |
Output is correct |
53 |
Correct |
59 ms |
7212 KB |
Output is correct |
54 |
Correct |
54 ms |
7252 KB |
Output is correct |
55 |
Correct |
61 ms |
7096 KB |
Output is correct |
56 |
Correct |
60 ms |
7248 KB |
Output is correct |
57 |
Correct |
62 ms |
7168 KB |
Output is correct |
58 |
Correct |
57 ms |
7508 KB |
Output is correct |
59 |
Correct |
61 ms |
7252 KB |
Output is correct |
60 |
Correct |
62 ms |
7092 KB |
Output is correct |
61 |
Correct |
61 ms |
7252 KB |
Output is correct |
62 |
Correct |
62 ms |
7236 KB |
Output is correct |
63 |
Correct |
61 ms |
7248 KB |
Output is correct |
64 |
Correct |
62 ms |
7228 KB |
Output is correct |
65 |
Correct |
61 ms |
7248 KB |
Output is correct |
66 |
Correct |
65 ms |
7096 KB |
Output is correct |
67 |
Correct |
58 ms |
7248 KB |
Output is correct |
68 |
Correct |
67 ms |
7252 KB |
Output is correct |
69 |
Correct |
168 ms |
17676 KB |
Output is correct |
70 |
Correct |
211 ms |
16564 KB |
Output is correct |
71 |
Correct |
98 ms |
12632 KB |
Output is correct |
72 |
Correct |
95 ms |
12100 KB |
Output is correct |
73 |
Correct |
95 ms |
12056 KB |
Output is correct |
74 |
Correct |
130 ms |
17788 KB |
Output is correct |
75 |
Correct |
98 ms |
12420 KB |
Output is correct |
76 |
Correct |
144 ms |
18220 KB |
Output is correct |
77 |
Correct |
140 ms |
17916 KB |
Output is correct |
78 |
Correct |
96 ms |
12112 KB |
Output is correct |
79 |
Correct |
102 ms |
12112 KB |
Output is correct |
80 |
Correct |
131 ms |
17432 KB |
Output is correct |
81 |
Correct |
98 ms |
12092 KB |
Output is correct |
82 |
Correct |
148 ms |
18360 KB |
Output is correct |
83 |
Correct |
146 ms |
19696 KB |
Output is correct |
84 |
Correct |
96 ms |
12884 KB |
Output is correct |
85 |
Correct |
99 ms |
12852 KB |
Output is correct |
86 |
Correct |
168 ms |
19284 KB |
Output is correct |
87 |
Correct |
161 ms |
19792 KB |
Output is correct |
88 |
Correct |
102 ms |
13196 KB |
Output is correct |
89 |
Correct |
151 ms |
19372 KB |
Output is correct |
90 |
Correct |
155 ms |
19876 KB |
Output is correct |
91 |
Correct |
107 ms |
12848 KB |
Output is correct |
92 |
Correct |
135 ms |
19096 KB |
Output is correct |
93 |
Correct |
98 ms |
13136 KB |
Output is correct |
94 |
Correct |
95 ms |
12884 KB |
Output is correct |
95 |
Correct |
103 ms |
13216 KB |
Output is correct |
96 |
Correct |
165 ms |
19892 KB |
Output is correct |
97 |
Correct |
121 ms |
17804 KB |
Output is correct |
98 |
Correct |
133 ms |
14968 KB |
Output is correct |
99 |
Correct |
203 ms |
20068 KB |
Output is correct |
100 |
Correct |
66 ms |
15124 KB |
Output is correct |