#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)));
a.push_back(Cross(sb, Cross(sa, sc)));
a.push_back(Cross(sc, Cross(sb, sa)));
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 |
2416 KB |
Output is correct |
2 |
Correct |
79 ms |
2428 KB |
Output is correct |
3 |
Correct |
87 ms |
2456 KB |
Output is correct |
4 |
Correct |
66 ms |
2436 KB |
Output is correct |
5 |
Correct |
65 ms |
2412 KB |
Output is correct |
6 |
Correct |
73 ms |
2404 KB |
Output is correct |
7 |
Correct |
71 ms |
2456 KB |
Output is correct |
8 |
Correct |
70 ms |
2476 KB |
Output is correct |
9 |
Correct |
70 ms |
2444 KB |
Output is correct |
10 |
Correct |
76 ms |
2476 KB |
Output is correct |
11 |
Correct |
82 ms |
2472 KB |
Output is correct |
12 |
Correct |
67 ms |
2384 KB |
Output is correct |
13 |
Correct |
67 ms |
2384 KB |
Output is correct |
14 |
Correct |
70 ms |
2484 KB |
Output is correct |
15 |
Correct |
94 ms |
2400 KB |
Output is correct |
16 |
Correct |
72 ms |
2508 KB |
Output is correct |
17 |
Correct |
67 ms |
2444 KB |
Output is correct |
18 |
Correct |
72 ms |
2480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2416 KB |
Output is correct |
2 |
Correct |
79 ms |
2428 KB |
Output is correct |
3 |
Correct |
87 ms |
2456 KB |
Output is correct |
4 |
Correct |
66 ms |
2436 KB |
Output is correct |
5 |
Correct |
65 ms |
2412 KB |
Output is correct |
6 |
Correct |
73 ms |
2404 KB |
Output is correct |
7 |
Correct |
71 ms |
2456 KB |
Output is correct |
8 |
Correct |
70 ms |
2476 KB |
Output is correct |
9 |
Correct |
70 ms |
2444 KB |
Output is correct |
10 |
Correct |
76 ms |
2476 KB |
Output is correct |
11 |
Correct |
82 ms |
2472 KB |
Output is correct |
12 |
Correct |
67 ms |
2384 KB |
Output is correct |
13 |
Correct |
67 ms |
2384 KB |
Output is correct |
14 |
Correct |
70 ms |
2484 KB |
Output is correct |
15 |
Correct |
94 ms |
2400 KB |
Output is correct |
16 |
Correct |
72 ms |
2508 KB |
Output is correct |
17 |
Correct |
67 ms |
2444 KB |
Output is correct |
18 |
Correct |
72 ms |
2480 KB |
Output is correct |
19 |
Correct |
224 ms |
10540 KB |
Output is correct |
20 |
Correct |
221 ms |
8468 KB |
Output is correct |
21 |
Correct |
163 ms |
10260 KB |
Output is correct |
22 |
Correct |
144 ms |
9940 KB |
Output is correct |
23 |
Correct |
107 ms |
2992 KB |
Output is correct |
24 |
Correct |
109 ms |
2912 KB |
Output is correct |
25 |
Correct |
155 ms |
10528 KB |
Output is correct |
26 |
Correct |
184 ms |
10412 KB |
Output is correct |
27 |
Correct |
191 ms |
10632 KB |
Output is correct |
28 |
Correct |
165 ms |
10432 KB |
Output is correct |
29 |
Correct |
180 ms |
10448 KB |
Output is correct |
30 |
Correct |
108 ms |
3188 KB |
Output is correct |
31 |
Correct |
174 ms |
10504 KB |
Output is correct |
32 |
Correct |
208 ms |
10216 KB |
Output is correct |
33 |
Correct |
103 ms |
3004 KB |
Output is correct |
34 |
Correct |
202 ms |
10448 KB |
Output is correct |
35 |
Correct |
133 ms |
9664 KB |
Output is correct |
36 |
Correct |
98 ms |
2972 KB |
Output is correct |
37 |
Correct |
97 ms |
2996 KB |
Output is correct |
38 |
Correct |
246 ms |
8484 KB |
Output is correct |
39 |
Correct |
123 ms |
7916 KB |
Output is correct |
40 |
Correct |
146 ms |
7136 KB |
Output is correct |
41 |
Correct |
258 ms |
10700 KB |
Output is correct |
42 |
Correct |
63 ms |
8112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2416 KB |
Output is correct |
2 |
Correct |
79 ms |
2428 KB |
Output is correct |
3 |
Correct |
87 ms |
2456 KB |
Output is correct |
4 |
Correct |
66 ms |
2436 KB |
Output is correct |
5 |
Correct |
65 ms |
2412 KB |
Output is correct |
6 |
Correct |
73 ms |
2404 KB |
Output is correct |
7 |
Correct |
71 ms |
2456 KB |
Output is correct |
8 |
Correct |
70 ms |
2476 KB |
Output is correct |
9 |
Correct |
70 ms |
2444 KB |
Output is correct |
10 |
Correct |
76 ms |
2476 KB |
Output is correct |
11 |
Correct |
82 ms |
2472 KB |
Output is correct |
12 |
Correct |
67 ms |
2384 KB |
Output is correct |
13 |
Correct |
67 ms |
2384 KB |
Output is correct |
14 |
Correct |
70 ms |
2484 KB |
Output is correct |
15 |
Correct |
94 ms |
2400 KB |
Output is correct |
16 |
Correct |
72 ms |
2508 KB |
Output is correct |
17 |
Correct |
67 ms |
2444 KB |
Output is correct |
18 |
Correct |
72 ms |
2480 KB |
Output is correct |
19 |
Correct |
82 ms |
2452 KB |
Output is correct |
20 |
Correct |
86 ms |
2428 KB |
Output is correct |
21 |
Correct |
69 ms |
2436 KB |
Output is correct |
22 |
Correct |
64 ms |
2440 KB |
Output is correct |
23 |
Correct |
82 ms |
2496 KB |
Output is correct |
24 |
Correct |
66 ms |
2460 KB |
Output is correct |
25 |
Correct |
69 ms |
2448 KB |
Output is correct |
26 |
Correct |
69 ms |
2448 KB |
Output is correct |
27 |
Correct |
89 ms |
2500 KB |
Output is correct |
28 |
Correct |
60 ms |
2344 KB |
Output is correct |
29 |
Correct |
68 ms |
2480 KB |
Output is correct |
30 |
Correct |
69 ms |
2384 KB |
Output is correct |
31 |
Correct |
84 ms |
2400 KB |
Output is correct |
32 |
Correct |
71 ms |
3948 KB |
Output is correct |
33 |
Correct |
81 ms |
4012 KB |
Output is correct |
34 |
Correct |
86 ms |
3836 KB |
Output is correct |
35 |
Correct |
77 ms |
3948 KB |
Output is correct |
36 |
Correct |
74 ms |
4044 KB |
Output is correct |
37 |
Correct |
80 ms |
4028 KB |
Output is correct |
38 |
Correct |
86 ms |
3968 KB |
Output is correct |
39 |
Correct |
72 ms |
4016 KB |
Output is correct |
40 |
Correct |
74 ms |
3944 KB |
Output is correct |
41 |
Correct |
93 ms |
3940 KB |
Output is correct |
42 |
Correct |
80 ms |
4024 KB |
Output is correct |
43 |
Correct |
70 ms |
4068 KB |
Output is correct |
44 |
Correct |
74 ms |
4164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2416 KB |
Output is correct |
2 |
Correct |
79 ms |
2428 KB |
Output is correct |
3 |
Correct |
87 ms |
2456 KB |
Output is correct |
4 |
Correct |
66 ms |
2436 KB |
Output is correct |
5 |
Correct |
65 ms |
2412 KB |
Output is correct |
6 |
Correct |
73 ms |
2404 KB |
Output is correct |
7 |
Correct |
71 ms |
2456 KB |
Output is correct |
8 |
Correct |
70 ms |
2476 KB |
Output is correct |
9 |
Correct |
70 ms |
2444 KB |
Output is correct |
10 |
Correct |
76 ms |
2476 KB |
Output is correct |
11 |
Correct |
82 ms |
2472 KB |
Output is correct |
12 |
Correct |
67 ms |
2384 KB |
Output is correct |
13 |
Correct |
67 ms |
2384 KB |
Output is correct |
14 |
Correct |
70 ms |
2484 KB |
Output is correct |
15 |
Correct |
94 ms |
2400 KB |
Output is correct |
16 |
Correct |
72 ms |
2508 KB |
Output is correct |
17 |
Correct |
67 ms |
2444 KB |
Output is correct |
18 |
Correct |
72 ms |
2480 KB |
Output is correct |
19 |
Correct |
224 ms |
10540 KB |
Output is correct |
20 |
Correct |
221 ms |
8468 KB |
Output is correct |
21 |
Correct |
163 ms |
10260 KB |
Output is correct |
22 |
Correct |
144 ms |
9940 KB |
Output is correct |
23 |
Correct |
107 ms |
2992 KB |
Output is correct |
24 |
Correct |
109 ms |
2912 KB |
Output is correct |
25 |
Correct |
155 ms |
10528 KB |
Output is correct |
26 |
Correct |
184 ms |
10412 KB |
Output is correct |
27 |
Correct |
191 ms |
10632 KB |
Output is correct |
28 |
Correct |
165 ms |
10432 KB |
Output is correct |
29 |
Correct |
180 ms |
10448 KB |
Output is correct |
30 |
Correct |
108 ms |
3188 KB |
Output is correct |
31 |
Correct |
174 ms |
10504 KB |
Output is correct |
32 |
Correct |
208 ms |
10216 KB |
Output is correct |
33 |
Correct |
103 ms |
3004 KB |
Output is correct |
34 |
Correct |
202 ms |
10448 KB |
Output is correct |
35 |
Correct |
133 ms |
9664 KB |
Output is correct |
36 |
Correct |
98 ms |
2972 KB |
Output is correct |
37 |
Correct |
97 ms |
2996 KB |
Output is correct |
38 |
Correct |
246 ms |
8484 KB |
Output is correct |
39 |
Correct |
123 ms |
7916 KB |
Output is correct |
40 |
Correct |
146 ms |
7136 KB |
Output is correct |
41 |
Correct |
258 ms |
10700 KB |
Output is correct |
42 |
Correct |
63 ms |
8112 KB |
Output is correct |
43 |
Correct |
82 ms |
2452 KB |
Output is correct |
44 |
Correct |
86 ms |
2428 KB |
Output is correct |
45 |
Correct |
69 ms |
2436 KB |
Output is correct |
46 |
Correct |
64 ms |
2440 KB |
Output is correct |
47 |
Correct |
82 ms |
2496 KB |
Output is correct |
48 |
Correct |
66 ms |
2460 KB |
Output is correct |
49 |
Correct |
69 ms |
2448 KB |
Output is correct |
50 |
Correct |
69 ms |
2448 KB |
Output is correct |
51 |
Correct |
89 ms |
2500 KB |
Output is correct |
52 |
Correct |
60 ms |
2344 KB |
Output is correct |
53 |
Correct |
68 ms |
2480 KB |
Output is correct |
54 |
Correct |
69 ms |
2384 KB |
Output is correct |
55 |
Correct |
84 ms |
2400 KB |
Output is correct |
56 |
Correct |
71 ms |
3948 KB |
Output is correct |
57 |
Correct |
81 ms |
4012 KB |
Output is correct |
58 |
Correct |
86 ms |
3836 KB |
Output is correct |
59 |
Correct |
77 ms |
3948 KB |
Output is correct |
60 |
Correct |
74 ms |
4044 KB |
Output is correct |
61 |
Correct |
80 ms |
4028 KB |
Output is correct |
62 |
Correct |
86 ms |
3968 KB |
Output is correct |
63 |
Correct |
72 ms |
4016 KB |
Output is correct |
64 |
Correct |
74 ms |
3944 KB |
Output is correct |
65 |
Correct |
93 ms |
3940 KB |
Output is correct |
66 |
Correct |
80 ms |
4024 KB |
Output is correct |
67 |
Correct |
70 ms |
4068 KB |
Output is correct |
68 |
Correct |
74 ms |
4164 KB |
Output is correct |
69 |
Correct |
247 ms |
13164 KB |
Output is correct |
70 |
Correct |
228 ms |
12156 KB |
Output is correct |
71 |
Correct |
102 ms |
5416 KB |
Output is correct |
72 |
Correct |
106 ms |
5324 KB |
Output is correct |
73 |
Correct |
111 ms |
5272 KB |
Output is correct |
74 |
Correct |
159 ms |
13252 KB |
Output is correct |
75 |
Correct |
109 ms |
5264 KB |
Output is correct |
76 |
Correct |
211 ms |
14148 KB |
Output is correct |
77 |
Correct |
170 ms |
13316 KB |
Output is correct |
78 |
Correct |
101 ms |
5352 KB |
Output is correct |
79 |
Correct |
142 ms |
5324 KB |
Output is correct |
80 |
Correct |
144 ms |
12752 KB |
Output is correct |
81 |
Correct |
117 ms |
5376 KB |
Output is correct |
82 |
Correct |
184 ms |
14216 KB |
Output is correct |
83 |
Correct |
160 ms |
13896 KB |
Output is correct |
84 |
Correct |
105 ms |
5316 KB |
Output is correct |
85 |
Correct |
113 ms |
5340 KB |
Output is correct |
86 |
Correct |
172 ms |
13040 KB |
Output is correct |
87 |
Correct |
255 ms |
14224 KB |
Output is correct |
88 |
Correct |
112 ms |
5244 KB |
Output is correct |
89 |
Correct |
161 ms |
13520 KB |
Output is correct |
90 |
Correct |
207 ms |
14112 KB |
Output is correct |
91 |
Correct |
116 ms |
5324 KB |
Output is correct |
92 |
Correct |
150 ms |
12924 KB |
Output is correct |
93 |
Correct |
119 ms |
5340 KB |
Output is correct |
94 |
Correct |
108 ms |
5348 KB |
Output is correct |
95 |
Correct |
106 ms |
5368 KB |
Output is correct |
96 |
Correct |
205 ms |
11968 KB |
Output is correct |
97 |
Correct |
135 ms |
11632 KB |
Output is correct |
98 |
Correct |
148 ms |
10568 KB |
Output is correct |
99 |
Correct |
305 ms |
14344 KB |
Output is correct |
100 |
Correct |
81 ms |
11104 KB |
Output is correct |