#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
int n;
const int N = 2e5 + 5;
const int L = (1 << 19);
const int possi[9][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1},
{2, 2, 0}, {2, 0, 2}, {0, 2, 2},
{2, 1, 1}, {1, 2, 1}, {1, 1, 2}};
bool seg[L][4][9];
int lazy[L];
string s[3];
int inted(char c) {
if (c == 'J') {
return 0;
}
if (c == 'O') {
return 1;
}
if (c == 'I') {
return 2;
}
return -1;
}
void applyind(int ind, int c) {
for (int f = 0; f < 9; f++) {
seg[ind][3][f] = seg[ind][c][f];
}
lazy[ind] = c;
}
void apply(int ind) {
if (lazy[ind] != -1) {
applyind(2 * ind, lazy[ind]);
applyind(2 * ind + 1, lazy[ind]);
lazy[ind] = -1;
}
}
void cre(int l, int r, int ind) {
if (l == r) {
for (int f = 0; f < 9; f++) {
int c = 0;
for (int st = 0; st < 3; st++) {
c += possi[f][st] * inted(s[st][l]);
}
seg[ind][c % 3][f] = true;
}
lazy[ind] = -1;
return;
}
int m = (l + r) / 2;
cre(l, m, 2 * ind);
cre(m + 1, r, 2 * ind + 1);
for (int c = 0; c < 4; c++) {
for (int f = 0; f < 9; f++) {
seg[ind][c][f] = (seg[2 * ind][c][f] && seg[2 * ind + 1][c][f]);
}
}
lazy[ind] = -1;
}
void upd(int b, int e, int c, int l, int r, int ind) {
if (b <= l && r <= e) {
applyind(ind, c);
return;
}
if (e < l || r < b) {
return;
}
apply(ind);
int m = (l + r) / 2;
upd(b, e, c, l, m, 2 * ind);
upd(b, e, c, m + 1, r, 2 * ind + 1);
for (int f = 0; f < 9; f++) {
seg[ind][3][f] = (seg[2 * ind][3][f] && seg[2 * ind + 1][3][f]);
}
}
void answ() {
for (int f = 0; f < 9; f++) {
if (seg[1][3][f]) {
cout << "Yes" << endl;
return;
}
}
cout << "No" << endl;
}
void init() {
}
void input() {
cin >> n;
cin >> s[0] >> s[1] >> s[2];
}
void solve() {
cre(0, n - 1, 1);
int q;
cin >> q;
string t;
cin >> t;
for (int i = 0; i < n; i++) {
upd(i, i, inted(t[i]), 0, n - 1, 1);
}
answ();
while (q--) {
int b, e;
char c;
cin >> b >> e >> c;
upd(b - 1, e - 1, inted(c), 0, n - 1, 1);
answ();
}
}
void output() {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int number_of_testcases = 1;
//cin >> number_of_testcases;
while (number_of_testcases--) {
init();
input();
solve();
output();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
2288 KB |
Output is correct |
2 |
Correct |
131 ms |
2460 KB |
Output is correct |
3 |
Correct |
104 ms |
2212 KB |
Output is correct |
4 |
Correct |
83 ms |
2492 KB |
Output is correct |
5 |
Correct |
82 ms |
2248 KB |
Output is correct |
6 |
Correct |
88 ms |
2312 KB |
Output is correct |
7 |
Correct |
90 ms |
2380 KB |
Output is correct |
8 |
Correct |
84 ms |
2416 KB |
Output is correct |
9 |
Correct |
87 ms |
2424 KB |
Output is correct |
10 |
Correct |
99 ms |
2388 KB |
Output is correct |
11 |
Correct |
83 ms |
2368 KB |
Output is correct |
12 |
Correct |
90 ms |
2364 KB |
Output is correct |
13 |
Correct |
93 ms |
2460 KB |
Output is correct |
14 |
Correct |
86 ms |
2428 KB |
Output is correct |
15 |
Correct |
85 ms |
2460 KB |
Output is correct |
16 |
Correct |
84 ms |
2456 KB |
Output is correct |
17 |
Correct |
85 ms |
2348 KB |
Output is correct |
18 |
Correct |
106 ms |
2288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
2288 KB |
Output is correct |
2 |
Correct |
131 ms |
2460 KB |
Output is correct |
3 |
Correct |
104 ms |
2212 KB |
Output is correct |
4 |
Correct |
83 ms |
2492 KB |
Output is correct |
5 |
Correct |
82 ms |
2248 KB |
Output is correct |
6 |
Correct |
88 ms |
2312 KB |
Output is correct |
7 |
Correct |
90 ms |
2380 KB |
Output is correct |
8 |
Correct |
84 ms |
2416 KB |
Output is correct |
9 |
Correct |
87 ms |
2424 KB |
Output is correct |
10 |
Correct |
99 ms |
2388 KB |
Output is correct |
11 |
Correct |
83 ms |
2368 KB |
Output is correct |
12 |
Correct |
90 ms |
2364 KB |
Output is correct |
13 |
Correct |
93 ms |
2460 KB |
Output is correct |
14 |
Correct |
86 ms |
2428 KB |
Output is correct |
15 |
Correct |
85 ms |
2460 KB |
Output is correct |
16 |
Correct |
84 ms |
2456 KB |
Output is correct |
17 |
Correct |
85 ms |
2348 KB |
Output is correct |
18 |
Correct |
106 ms |
2288 KB |
Output is correct |
19 |
Correct |
440 ms |
26148 KB |
Output is correct |
20 |
Correct |
426 ms |
25904 KB |
Output is correct |
21 |
Correct |
357 ms |
25712 KB |
Output is correct |
22 |
Correct |
291 ms |
25460 KB |
Output is correct |
23 |
Correct |
187 ms |
4552 KB |
Output is correct |
24 |
Correct |
150 ms |
4588 KB |
Output is correct |
25 |
Correct |
346 ms |
26012 KB |
Output is correct |
26 |
Correct |
370 ms |
26036 KB |
Output is correct |
27 |
Correct |
362 ms |
25952 KB |
Output is correct |
28 |
Correct |
349 ms |
26012 KB |
Output is correct |
29 |
Correct |
338 ms |
25948 KB |
Output is correct |
30 |
Correct |
163 ms |
4712 KB |
Output is correct |
31 |
Correct |
343 ms |
25928 KB |
Output is correct |
32 |
Correct |
378 ms |
25748 KB |
Output is correct |
33 |
Correct |
170 ms |
4688 KB |
Output is correct |
34 |
Correct |
365 ms |
25988 KB |
Output is correct |
35 |
Correct |
290 ms |
25248 KB |
Output is correct |
36 |
Correct |
140 ms |
4552 KB |
Output is correct |
37 |
Correct |
142 ms |
4556 KB |
Output is correct |
38 |
Correct |
357 ms |
25828 KB |
Output is correct |
39 |
Correct |
258 ms |
26076 KB |
Output is correct |
40 |
Correct |
299 ms |
15060 KB |
Output is correct |
41 |
Correct |
474 ms |
26204 KB |
Output is correct |
42 |
Correct |
144 ms |
25360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
2288 KB |
Output is correct |
2 |
Correct |
131 ms |
2460 KB |
Output is correct |
3 |
Correct |
104 ms |
2212 KB |
Output is correct |
4 |
Correct |
83 ms |
2492 KB |
Output is correct |
5 |
Correct |
82 ms |
2248 KB |
Output is correct |
6 |
Correct |
88 ms |
2312 KB |
Output is correct |
7 |
Correct |
90 ms |
2380 KB |
Output is correct |
8 |
Correct |
84 ms |
2416 KB |
Output is correct |
9 |
Correct |
87 ms |
2424 KB |
Output is correct |
10 |
Correct |
99 ms |
2388 KB |
Output is correct |
11 |
Correct |
83 ms |
2368 KB |
Output is correct |
12 |
Correct |
90 ms |
2364 KB |
Output is correct |
13 |
Correct |
93 ms |
2460 KB |
Output is correct |
14 |
Correct |
86 ms |
2428 KB |
Output is correct |
15 |
Correct |
85 ms |
2460 KB |
Output is correct |
16 |
Correct |
84 ms |
2456 KB |
Output is correct |
17 |
Correct |
85 ms |
2348 KB |
Output is correct |
18 |
Correct |
106 ms |
2288 KB |
Output is correct |
19 |
Correct |
98 ms |
2312 KB |
Output is correct |
20 |
Correct |
109 ms |
2356 KB |
Output is correct |
21 |
Correct |
86 ms |
2460 KB |
Output is correct |
22 |
Correct |
79 ms |
2208 KB |
Output is correct |
23 |
Correct |
86 ms |
2416 KB |
Output is correct |
24 |
Correct |
82 ms |
2368 KB |
Output is correct |
25 |
Correct |
89 ms |
2380 KB |
Output is correct |
26 |
Correct |
101 ms |
2296 KB |
Output is correct |
27 |
Correct |
85 ms |
2400 KB |
Output is correct |
28 |
Correct |
84 ms |
2172 KB |
Output is correct |
29 |
Correct |
102 ms |
2404 KB |
Output is correct |
30 |
Correct |
84 ms |
2232 KB |
Output is correct |
31 |
Correct |
98 ms |
2448 KB |
Output is correct |
32 |
Correct |
93 ms |
2380 KB |
Output is correct |
33 |
Correct |
107 ms |
2528 KB |
Output is correct |
34 |
Correct |
84 ms |
2252 KB |
Output is correct |
35 |
Correct |
99 ms |
2416 KB |
Output is correct |
36 |
Correct |
89 ms |
2460 KB |
Output is correct |
37 |
Correct |
91 ms |
2428 KB |
Output is correct |
38 |
Correct |
92 ms |
2436 KB |
Output is correct |
39 |
Correct |
106 ms |
2552 KB |
Output is correct |
40 |
Correct |
87 ms |
2452 KB |
Output is correct |
41 |
Correct |
89 ms |
2468 KB |
Output is correct |
42 |
Correct |
120 ms |
2420 KB |
Output is correct |
43 |
Correct |
86 ms |
2376 KB |
Output is correct |
44 |
Correct |
88 ms |
2380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
2288 KB |
Output is correct |
2 |
Correct |
131 ms |
2460 KB |
Output is correct |
3 |
Correct |
104 ms |
2212 KB |
Output is correct |
4 |
Correct |
83 ms |
2492 KB |
Output is correct |
5 |
Correct |
82 ms |
2248 KB |
Output is correct |
6 |
Correct |
88 ms |
2312 KB |
Output is correct |
7 |
Correct |
90 ms |
2380 KB |
Output is correct |
8 |
Correct |
84 ms |
2416 KB |
Output is correct |
9 |
Correct |
87 ms |
2424 KB |
Output is correct |
10 |
Correct |
99 ms |
2388 KB |
Output is correct |
11 |
Correct |
83 ms |
2368 KB |
Output is correct |
12 |
Correct |
90 ms |
2364 KB |
Output is correct |
13 |
Correct |
93 ms |
2460 KB |
Output is correct |
14 |
Correct |
86 ms |
2428 KB |
Output is correct |
15 |
Correct |
85 ms |
2460 KB |
Output is correct |
16 |
Correct |
84 ms |
2456 KB |
Output is correct |
17 |
Correct |
85 ms |
2348 KB |
Output is correct |
18 |
Correct |
106 ms |
2288 KB |
Output is correct |
19 |
Correct |
440 ms |
26148 KB |
Output is correct |
20 |
Correct |
426 ms |
25904 KB |
Output is correct |
21 |
Correct |
357 ms |
25712 KB |
Output is correct |
22 |
Correct |
291 ms |
25460 KB |
Output is correct |
23 |
Correct |
187 ms |
4552 KB |
Output is correct |
24 |
Correct |
150 ms |
4588 KB |
Output is correct |
25 |
Correct |
346 ms |
26012 KB |
Output is correct |
26 |
Correct |
370 ms |
26036 KB |
Output is correct |
27 |
Correct |
362 ms |
25952 KB |
Output is correct |
28 |
Correct |
349 ms |
26012 KB |
Output is correct |
29 |
Correct |
338 ms |
25948 KB |
Output is correct |
30 |
Correct |
163 ms |
4712 KB |
Output is correct |
31 |
Correct |
343 ms |
25928 KB |
Output is correct |
32 |
Correct |
378 ms |
25748 KB |
Output is correct |
33 |
Correct |
170 ms |
4688 KB |
Output is correct |
34 |
Correct |
365 ms |
25988 KB |
Output is correct |
35 |
Correct |
290 ms |
25248 KB |
Output is correct |
36 |
Correct |
140 ms |
4552 KB |
Output is correct |
37 |
Correct |
142 ms |
4556 KB |
Output is correct |
38 |
Correct |
357 ms |
25828 KB |
Output is correct |
39 |
Correct |
258 ms |
26076 KB |
Output is correct |
40 |
Correct |
299 ms |
15060 KB |
Output is correct |
41 |
Correct |
474 ms |
26204 KB |
Output is correct |
42 |
Correct |
144 ms |
25360 KB |
Output is correct |
43 |
Correct |
98 ms |
2312 KB |
Output is correct |
44 |
Correct |
109 ms |
2356 KB |
Output is correct |
45 |
Correct |
86 ms |
2460 KB |
Output is correct |
46 |
Correct |
79 ms |
2208 KB |
Output is correct |
47 |
Correct |
86 ms |
2416 KB |
Output is correct |
48 |
Correct |
82 ms |
2368 KB |
Output is correct |
49 |
Correct |
89 ms |
2380 KB |
Output is correct |
50 |
Correct |
101 ms |
2296 KB |
Output is correct |
51 |
Correct |
85 ms |
2400 KB |
Output is correct |
52 |
Correct |
84 ms |
2172 KB |
Output is correct |
53 |
Correct |
102 ms |
2404 KB |
Output is correct |
54 |
Correct |
84 ms |
2232 KB |
Output is correct |
55 |
Correct |
98 ms |
2448 KB |
Output is correct |
56 |
Correct |
93 ms |
2380 KB |
Output is correct |
57 |
Correct |
107 ms |
2528 KB |
Output is correct |
58 |
Correct |
84 ms |
2252 KB |
Output is correct |
59 |
Correct |
99 ms |
2416 KB |
Output is correct |
60 |
Correct |
89 ms |
2460 KB |
Output is correct |
61 |
Correct |
91 ms |
2428 KB |
Output is correct |
62 |
Correct |
92 ms |
2436 KB |
Output is correct |
63 |
Correct |
106 ms |
2552 KB |
Output is correct |
64 |
Correct |
87 ms |
2452 KB |
Output is correct |
65 |
Correct |
89 ms |
2468 KB |
Output is correct |
66 |
Correct |
120 ms |
2420 KB |
Output is correct |
67 |
Correct |
86 ms |
2376 KB |
Output is correct |
68 |
Correct |
88 ms |
2380 KB |
Output is correct |
69 |
Correct |
405 ms |
25400 KB |
Output is correct |
70 |
Correct |
410 ms |
25928 KB |
Output is correct |
71 |
Correct |
164 ms |
4560 KB |
Output is correct |
72 |
Correct |
142 ms |
4608 KB |
Output is correct |
73 |
Correct |
171 ms |
4684 KB |
Output is correct |
74 |
Correct |
333 ms |
25572 KB |
Output is correct |
75 |
Correct |
134 ms |
4484 KB |
Output is correct |
76 |
Correct |
339 ms |
25932 KB |
Output is correct |
77 |
Correct |
311 ms |
25572 KB |
Output is correct |
78 |
Correct |
151 ms |
4588 KB |
Output is correct |
79 |
Correct |
144 ms |
4684 KB |
Output is correct |
80 |
Correct |
342 ms |
25220 KB |
Output is correct |
81 |
Correct |
148 ms |
4536 KB |
Output is correct |
82 |
Correct |
333 ms |
25996 KB |
Output is correct |
83 |
Correct |
339 ms |
25776 KB |
Output is correct |
84 |
Correct |
163 ms |
4572 KB |
Output is correct |
85 |
Correct |
149 ms |
4520 KB |
Output is correct |
86 |
Correct |
336 ms |
25444 KB |
Output is correct |
87 |
Correct |
365 ms |
26040 KB |
Output is correct |
88 |
Correct |
168 ms |
4556 KB |
Output is correct |
89 |
Correct |
328 ms |
25572 KB |
Output is correct |
90 |
Correct |
427 ms |
26012 KB |
Output is correct |
91 |
Correct |
162 ms |
4592 KB |
Output is correct |
92 |
Correct |
333 ms |
25300 KB |
Output is correct |
93 |
Correct |
154 ms |
4508 KB |
Output is correct |
94 |
Correct |
148 ms |
4544 KB |
Output is correct |
95 |
Correct |
151 ms |
4556 KB |
Output is correct |
96 |
Correct |
349 ms |
25832 KB |
Output is correct |
97 |
Correct |
264 ms |
26080 KB |
Output is correct |
98 |
Correct |
315 ms |
15104 KB |
Output is correct |
99 |
Correct |
521 ms |
26360 KB |
Output is correct |
100 |
Correct |
168 ms |
25440 KB |
Output is correct |