#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int MD = 1e9 + 7;
const int BASE = 77777;
int mul(int x, int y) {
return (long long) x * y % MD;
}
int add(int x, int y) {
return x + y >= MD ? x + y - MD : x + y;
}
int sub(int x, int y) {
return x - y < 0 ? x - y + MD : x - y;
}
int st[4 * N], lzy[4 * N], pw[N], pref[N];
bool act[4 * N];
void build(int node, int l, int r, string& s) {
if (l == r) {
st[node] = mul((s[l] - '0'), pw[l]);
return;
}
int mid = l + r >> 1;
build(node + node, l, mid, s);
build(node + node + 1, mid + 1, r, s);
st[node] = add(st[node + node], st[node + node + 1]);
}
void push(int node, int l, int r) {
if (!act[node]) {
return;
}
if (l != r) {
int mid = l + r >> 1;
st[node + node] = mul(lzy[node], sub(pref[mid], (l == 0 ? 0 : pref[l - 1])));
st[node + node + 1] = mul(lzy[node], sub(pref[r], pref[mid]));
lzy[node + node] = lzy[node];
lzy[node + node + 1] = lzy[node];
act[node + node] = true;
act[node + node + 1] = true;
}
act[node] = false;
}
void modify(int node, int l, int r, int ll, int rr, char cc) {
if (l > r || l > rr || r < ll) return;
if (ll <= l && r <= rr) {
st[node] = mul(cc - '0', sub(pref[r], (l == 0 ? 0 : pref[l - 1])));
lzy[node] = cc - '0';
act[node] = true;
return;
}
push(node, l, r);
int mid = l + r >> 1;
modify(node + node, l, mid, ll, rr, cc);
modify(node + node + 1, mid + 1, r, ll, rr, cc);
st[node] = add(st[node + node], st[node + node + 1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
pw[0] = 1;
pref[0] = 1;
for (int i = 1; i < N; i++) {
pw[i] = mul(pw[i - 1], BASE);
pref[i] = add(pref[i - 1], pw[i]);
}
int n;
cin >> n;
string sa, sb, sc;
cin >> sa >> sb >> sc;
for (int i = 0; i < n; i++) {
sa[i] = (sa[i] == 'J' ? '0' : (sa[i] == 'O' ? '1' : '2'));
sb[i] = (sb[i] == 'J' ? '0' : (sb[i] == 'O' ? '1' : '2'));
sc[i] = (sc[i] == 'J' ? '0' : (sc[i] == 'O' ? '1' : '2'));
}
auto Cross = [&](string s, string t) {
string res = "";
for (int i = 0; i < n; i++) {
if (s[i] == t[i]) {
res += s[i];
} else {
res += (s[i] ^ t[i] ^ '0' ^ '1' ^ '2');
}
}
return res;
};
vector<string> a;
a.push_back(sa);
a.push_back(sb);
a.push_back(sc);
a.push_back(Cross(sa, sb));
a.push_back(Cross(sa, sc));
a.push_back(Cross(sb, sc));
a.push_back(Cross(sa, Cross(sb, sc)));
set<int> hsh;
auto GetHash = [&](string s) {
int res = 0;
for (int i = 0; i < n; i++) {
res = add(res, mul(s[i] - '0', pw[i]));
}
return res;
};
for (auto &str : a) {
hsh.insert(GetHash(str));
}
int q;
cin >> q;
string t;
cin >> t;
for (int i = 0; i < n; i++) {
t[i] = (t[i] == 'J' ? '0' : (t[i] == 'O' ? '1' : '2'));
}
build(1, 0, n - 1, t);
function<void()> Answer = [&]() {
int my = st[1];
bool ok = false;
for (auto he : hsh) {
ok |= (he == my);
}
cout << (ok ? "Yes" : "No") << '\n';
};
Answer();
while (q--) {
int l, r;
char foo;
cin >> l >> r >> foo;
--l; --r;
foo = (foo == 'J' ? '0' : (foo == 'O' ? '1' : '2'));
modify(1, 0, n - 1, l, r, foo);
Answer();
}
return 0;
}
Compilation message
Main.cpp: In function 'void build(int, int, int, std::string&)':
Main.cpp:29:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void push(int, int, int)':
Main.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void modify(int, int, int, int, int, char)':
Main.cpp:60:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
60 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2516 KB |
Output is correct |
2 |
Correct |
77 ms |
2496 KB |
Output is correct |
3 |
Correct |
81 ms |
2424 KB |
Output is correct |
4 |
Correct |
65 ms |
2428 KB |
Output is correct |
5 |
Correct |
67 ms |
2468 KB |
Output is correct |
6 |
Correct |
68 ms |
2400 KB |
Output is correct |
7 |
Correct |
63 ms |
2380 KB |
Output is correct |
8 |
Correct |
69 ms |
2508 KB |
Output is correct |
9 |
Correct |
69 ms |
2432 KB |
Output is correct |
10 |
Correct |
71 ms |
2484 KB |
Output is correct |
11 |
Correct |
74 ms |
2380 KB |
Output is correct |
12 |
Correct |
68 ms |
2420 KB |
Output is correct |
13 |
Correct |
68 ms |
2380 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
68 ms |
2444 KB |
Output is correct |
16 |
Correct |
67 ms |
2460 KB |
Output is correct |
17 |
Correct |
71 ms |
2480 KB |
Output is correct |
18 |
Correct |
75 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2516 KB |
Output is correct |
2 |
Correct |
77 ms |
2496 KB |
Output is correct |
3 |
Correct |
81 ms |
2424 KB |
Output is correct |
4 |
Correct |
65 ms |
2428 KB |
Output is correct |
5 |
Correct |
67 ms |
2468 KB |
Output is correct |
6 |
Correct |
68 ms |
2400 KB |
Output is correct |
7 |
Correct |
63 ms |
2380 KB |
Output is correct |
8 |
Correct |
69 ms |
2508 KB |
Output is correct |
9 |
Correct |
69 ms |
2432 KB |
Output is correct |
10 |
Correct |
71 ms |
2484 KB |
Output is correct |
11 |
Correct |
74 ms |
2380 KB |
Output is correct |
12 |
Correct |
68 ms |
2420 KB |
Output is correct |
13 |
Correct |
68 ms |
2380 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
68 ms |
2444 KB |
Output is correct |
16 |
Correct |
67 ms |
2460 KB |
Output is correct |
17 |
Correct |
71 ms |
2480 KB |
Output is correct |
18 |
Correct |
75 ms |
2508 KB |
Output is correct |
19 |
Correct |
222 ms |
10632 KB |
Output is correct |
20 |
Correct |
250 ms |
11312 KB |
Output is correct |
21 |
Correct |
168 ms |
13084 KB |
Output is correct |
22 |
Correct |
190 ms |
12880 KB |
Output is correct |
23 |
Correct |
111 ms |
5244 KB |
Output is correct |
24 |
Correct |
111 ms |
5248 KB |
Output is correct |
25 |
Correct |
170 ms |
13320 KB |
Output is correct |
26 |
Correct |
183 ms |
13476 KB |
Output is correct |
27 |
Correct |
212 ms |
13348 KB |
Output is correct |
28 |
Correct |
207 ms |
13340 KB |
Output is correct |
29 |
Correct |
202 ms |
13272 KB |
Output is correct |
30 |
Correct |
111 ms |
5308 KB |
Output is correct |
31 |
Correct |
265 ms |
13284 KB |
Output is correct |
32 |
Correct |
201 ms |
13212 KB |
Output is correct |
33 |
Correct |
121 ms |
5204 KB |
Output is correct |
34 |
Correct |
298 ms |
13320 KB |
Output is correct |
35 |
Correct |
165 ms |
12356 KB |
Output is correct |
36 |
Correct |
113 ms |
5232 KB |
Output is correct |
37 |
Correct |
115 ms |
5196 KB |
Output is correct |
38 |
Correct |
194 ms |
11188 KB |
Output is correct |
39 |
Correct |
158 ms |
10900 KB |
Output is correct |
40 |
Correct |
150 ms |
9968 KB |
Output is correct |
41 |
Correct |
306 ms |
13576 KB |
Output is correct |
42 |
Correct |
66 ms |
10248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2516 KB |
Output is correct |
2 |
Correct |
77 ms |
2496 KB |
Output is correct |
3 |
Correct |
81 ms |
2424 KB |
Output is correct |
4 |
Correct |
65 ms |
2428 KB |
Output is correct |
5 |
Correct |
67 ms |
2468 KB |
Output is correct |
6 |
Correct |
68 ms |
2400 KB |
Output is correct |
7 |
Correct |
63 ms |
2380 KB |
Output is correct |
8 |
Correct |
69 ms |
2508 KB |
Output is correct |
9 |
Correct |
69 ms |
2432 KB |
Output is correct |
10 |
Correct |
71 ms |
2484 KB |
Output is correct |
11 |
Correct |
74 ms |
2380 KB |
Output is correct |
12 |
Correct |
68 ms |
2420 KB |
Output is correct |
13 |
Correct |
68 ms |
2380 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
68 ms |
2444 KB |
Output is correct |
16 |
Correct |
67 ms |
2460 KB |
Output is correct |
17 |
Correct |
71 ms |
2480 KB |
Output is correct |
18 |
Correct |
75 ms |
2508 KB |
Output is correct |
19 |
Correct |
84 ms |
2428 KB |
Output is correct |
20 |
Correct |
82 ms |
2456 KB |
Output is correct |
21 |
Correct |
80 ms |
2508 KB |
Output is correct |
22 |
Correct |
71 ms |
2444 KB |
Output is correct |
23 |
Correct |
85 ms |
2416 KB |
Output is correct |
24 |
Correct |
79 ms |
2484 KB |
Output is correct |
25 |
Correct |
83 ms |
2496 KB |
Output is correct |
26 |
Correct |
78 ms |
2420 KB |
Output is correct |
27 |
Correct |
72 ms |
2432 KB |
Output is correct |
28 |
Correct |
66 ms |
2384 KB |
Output is correct |
29 |
Correct |
73 ms |
2496 KB |
Output is correct |
30 |
Correct |
73 ms |
2340 KB |
Output is correct |
31 |
Incorrect |
88 ms |
2448 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2516 KB |
Output is correct |
2 |
Correct |
77 ms |
2496 KB |
Output is correct |
3 |
Correct |
81 ms |
2424 KB |
Output is correct |
4 |
Correct |
65 ms |
2428 KB |
Output is correct |
5 |
Correct |
67 ms |
2468 KB |
Output is correct |
6 |
Correct |
68 ms |
2400 KB |
Output is correct |
7 |
Correct |
63 ms |
2380 KB |
Output is correct |
8 |
Correct |
69 ms |
2508 KB |
Output is correct |
9 |
Correct |
69 ms |
2432 KB |
Output is correct |
10 |
Correct |
71 ms |
2484 KB |
Output is correct |
11 |
Correct |
74 ms |
2380 KB |
Output is correct |
12 |
Correct |
68 ms |
2420 KB |
Output is correct |
13 |
Correct |
68 ms |
2380 KB |
Output is correct |
14 |
Correct |
70 ms |
2468 KB |
Output is correct |
15 |
Correct |
68 ms |
2444 KB |
Output is correct |
16 |
Correct |
67 ms |
2460 KB |
Output is correct |
17 |
Correct |
71 ms |
2480 KB |
Output is correct |
18 |
Correct |
75 ms |
2508 KB |
Output is correct |
19 |
Correct |
222 ms |
10632 KB |
Output is correct |
20 |
Correct |
250 ms |
11312 KB |
Output is correct |
21 |
Correct |
168 ms |
13084 KB |
Output is correct |
22 |
Correct |
190 ms |
12880 KB |
Output is correct |
23 |
Correct |
111 ms |
5244 KB |
Output is correct |
24 |
Correct |
111 ms |
5248 KB |
Output is correct |
25 |
Correct |
170 ms |
13320 KB |
Output is correct |
26 |
Correct |
183 ms |
13476 KB |
Output is correct |
27 |
Correct |
212 ms |
13348 KB |
Output is correct |
28 |
Correct |
207 ms |
13340 KB |
Output is correct |
29 |
Correct |
202 ms |
13272 KB |
Output is correct |
30 |
Correct |
111 ms |
5308 KB |
Output is correct |
31 |
Correct |
265 ms |
13284 KB |
Output is correct |
32 |
Correct |
201 ms |
13212 KB |
Output is correct |
33 |
Correct |
121 ms |
5204 KB |
Output is correct |
34 |
Correct |
298 ms |
13320 KB |
Output is correct |
35 |
Correct |
165 ms |
12356 KB |
Output is correct |
36 |
Correct |
113 ms |
5232 KB |
Output is correct |
37 |
Correct |
115 ms |
5196 KB |
Output is correct |
38 |
Correct |
194 ms |
11188 KB |
Output is correct |
39 |
Correct |
158 ms |
10900 KB |
Output is correct |
40 |
Correct |
150 ms |
9968 KB |
Output is correct |
41 |
Correct |
306 ms |
13576 KB |
Output is correct |
42 |
Correct |
66 ms |
10248 KB |
Output is correct |
43 |
Correct |
84 ms |
2428 KB |
Output is correct |
44 |
Correct |
82 ms |
2456 KB |
Output is correct |
45 |
Correct |
80 ms |
2508 KB |
Output is correct |
46 |
Correct |
71 ms |
2444 KB |
Output is correct |
47 |
Correct |
85 ms |
2416 KB |
Output is correct |
48 |
Correct |
79 ms |
2484 KB |
Output is correct |
49 |
Correct |
83 ms |
2496 KB |
Output is correct |
50 |
Correct |
78 ms |
2420 KB |
Output is correct |
51 |
Correct |
72 ms |
2432 KB |
Output is correct |
52 |
Correct |
66 ms |
2384 KB |
Output is correct |
53 |
Correct |
73 ms |
2496 KB |
Output is correct |
54 |
Correct |
73 ms |
2340 KB |
Output is correct |
55 |
Incorrect |
88 ms |
2448 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |