#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
using namespace std;
const int maxn = 2e5 + 5;
void transform(int A[], int B[], int C[], int sz) {
for(int i = 0; i < sz; ++i) {
if(A[i] == B[i]) C[i] = A[i];
else {
C[i] = 5 - A[i] - B[i];
}
}
}
int get(char c) {
if(c == 'J') return 0;
if(c == 'O') return 1;
if(c == 'I') return 2;
return -1;
}
struct SGT {
struct node {
int cnt[3][3], tag;
};
vector<node> tr;
SGT(int sz) : tr(sz << 2) {}
void pull(int x) {
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 3; ++j)
tr[x].cnt[i][j] = tr[(x << 1)].cnt[i][j] + tr[(x << 1) | 1].cnt[i][j];
}
}
void print(int x) {
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 3; ++j) {
printf("%d%c", tr[x].cnt[i][j], " \n"[j == 2]);
}
}
}
void apply(int x, int color) {
for(int i = 0; i < 3; ++i) {
int sum = 0;
for(int j = 0; j < 3; ++j) {
sum += tr[x].cnt[i][j];
}
for(int j = 0; j < 3; ++j) {
tr[x].cnt[i][j] = 0;
}
tr[x].cnt[i][color] = sum;
}
}
void push(int x) {
if(tr[x].tag != -1) {
// apply
apply(x << 1, tr[x].tag);
apply((x << 1) | 1, tr[x].tag);
// set tag
tr[x << 1].tag = tr[x].tag;
tr[(x << 1) | 1].tag = tr[x].tag;
tr[x].tag = -1;
// printf("pushed %d: \n", x << 1);
// print(x << 1);
// printf("pushed %d: \n", (x << 1) | 1);
// print((x << 1) | 1);
}
}
void build(int x, int L, int R, int ori[], int arr[]) {
tr[x].tag = -1;
if(L == R) {
memset(tr[x].cnt, 0, sizeof(int)*9);
tr[x].cnt[ori[L]][arr[L]]++;
// printf("build %d: \n", x);
// print(x);
return;
}
int mid = (L + R) >> 1;
build(x << 1, L, mid, ori, arr);
build((x << 1) | 1, mid + 1, R, ori, arr);
pull(x);
// printf("build %d: \n", x);
// print(x);
}
void upd(int x, int L, int R, int l, int r, int color) {
// printf("upd [%d, %d], %d, at [%d %d]\n", l, r, color, L, R);
if(l <= L && R <= r) {
apply(x, color);
tr[x].tag = color;
// printf("upded [%d, %d], %d, at [%d %d]\n", l, r, color, L, R);
// print(x);
return;
}
push(x);
int mid = (L + R) >> 1;
if(l <= mid) upd(x << 1, L, mid, l, r, color);
if(r > mid) upd((x << 1) | 1, mid + 1, R, l, r, color);
pull(x);
// printf("upded [%d, %d], %d, at [%d %d]\n", l, r, color, L, R);
// print(x);
}
int ask() {
int ret = 0;
for(int i = 0; i < 3; ++i) {
ret += tr[1].cnt[i][i];
}
return ret;
}
};
int S[3][maxn], T[maxn];
int n, q;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 0; i < 3; ++i) {
string s; cin >> s;
for(int j = 0; j < n; ++j) S[i][j] = get(s[j]);
}
cin >> q;
string t; cin >> t;
for(int i = 0; i < n; ++i) T[i] = get(t[i]);
SGT loli(n);
loli.build(1, 0, n - 1, S[0], T);
cout << (loli.ask() == n ? "Yes" : "No") << '\n';
for(int i = 0; i < q; ++i) {
int l, r, c; char _c;
cin >> l >> r >> _c; c = get(_c); l--, r--;
loli.upd(1, 0, n - 1, l, r, c);
cout << (loli.ask() == n ? "Yes" : "No") << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4436 KB |
Output is correct |
2 |
Correct |
70 ms |
4432 KB |
Output is correct |
3 |
Correct |
70 ms |
4432 KB |
Output is correct |
4 |
Correct |
60 ms |
4380 KB |
Output is correct |
5 |
Correct |
58 ms |
4452 KB |
Output is correct |
6 |
Correct |
58 ms |
4436 KB |
Output is correct |
7 |
Correct |
60 ms |
4444 KB |
Output is correct |
8 |
Correct |
62 ms |
4808 KB |
Output is correct |
9 |
Correct |
62 ms |
4440 KB |
Output is correct |
10 |
Correct |
62 ms |
4596 KB |
Output is correct |
11 |
Correct |
63 ms |
4624 KB |
Output is correct |
12 |
Correct |
62 ms |
4432 KB |
Output is correct |
13 |
Correct |
63 ms |
4432 KB |
Output is correct |
14 |
Correct |
63 ms |
4616 KB |
Output is correct |
15 |
Correct |
64 ms |
4640 KB |
Output is correct |
16 |
Correct |
65 ms |
4436 KB |
Output is correct |
17 |
Correct |
63 ms |
4640 KB |
Output is correct |
18 |
Correct |
67 ms |
4452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4436 KB |
Output is correct |
2 |
Correct |
70 ms |
4432 KB |
Output is correct |
3 |
Correct |
70 ms |
4432 KB |
Output is correct |
4 |
Correct |
60 ms |
4380 KB |
Output is correct |
5 |
Correct |
58 ms |
4452 KB |
Output is correct |
6 |
Correct |
58 ms |
4436 KB |
Output is correct |
7 |
Correct |
60 ms |
4444 KB |
Output is correct |
8 |
Correct |
62 ms |
4808 KB |
Output is correct |
9 |
Correct |
62 ms |
4440 KB |
Output is correct |
10 |
Correct |
62 ms |
4596 KB |
Output is correct |
11 |
Correct |
63 ms |
4624 KB |
Output is correct |
12 |
Correct |
62 ms |
4432 KB |
Output is correct |
13 |
Correct |
63 ms |
4432 KB |
Output is correct |
14 |
Correct |
63 ms |
4616 KB |
Output is correct |
15 |
Correct |
64 ms |
4640 KB |
Output is correct |
16 |
Correct |
65 ms |
4436 KB |
Output is correct |
17 |
Correct |
63 ms |
4640 KB |
Output is correct |
18 |
Correct |
67 ms |
4452 KB |
Output is correct |
19 |
Correct |
207 ms |
39164 KB |
Output is correct |
20 |
Correct |
202 ms |
39028 KB |
Output is correct |
21 |
Correct |
132 ms |
37268 KB |
Output is correct |
22 |
Correct |
132 ms |
33892 KB |
Output is correct |
23 |
Correct |
95 ms |
7104 KB |
Output is correct |
24 |
Correct |
99 ms |
6996 KB |
Output is correct |
25 |
Correct |
138 ms |
39224 KB |
Output is correct |
26 |
Correct |
144 ms |
39188 KB |
Output is correct |
27 |
Correct |
155 ms |
39024 KB |
Output is correct |
28 |
Correct |
169 ms |
39036 KB |
Output is correct |
29 |
Correct |
148 ms |
38216 KB |
Output is correct |
30 |
Correct |
105 ms |
7252 KB |
Output is correct |
31 |
Correct |
152 ms |
39040 KB |
Output is correct |
32 |
Correct |
190 ms |
36112 KB |
Output is correct |
33 |
Correct |
96 ms |
6996 KB |
Output is correct |
34 |
Correct |
161 ms |
39208 KB |
Output is correct |
35 |
Correct |
130 ms |
30236 KB |
Output is correct |
36 |
Correct |
96 ms |
6996 KB |
Output is correct |
37 |
Correct |
105 ms |
7112 KB |
Output is correct |
38 |
Correct |
183 ms |
38956 KB |
Output is correct |
39 |
Correct |
109 ms |
39152 KB |
Output is correct |
40 |
Correct |
158 ms |
27524 KB |
Output is correct |
41 |
Correct |
223 ms |
39392 KB |
Output is correct |
42 |
Correct |
52 ms |
38704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4436 KB |
Output is correct |
2 |
Correct |
70 ms |
4432 KB |
Output is correct |
3 |
Correct |
70 ms |
4432 KB |
Output is correct |
4 |
Correct |
60 ms |
4380 KB |
Output is correct |
5 |
Correct |
58 ms |
4452 KB |
Output is correct |
6 |
Correct |
58 ms |
4436 KB |
Output is correct |
7 |
Correct |
60 ms |
4444 KB |
Output is correct |
8 |
Correct |
62 ms |
4808 KB |
Output is correct |
9 |
Correct |
62 ms |
4440 KB |
Output is correct |
10 |
Correct |
62 ms |
4596 KB |
Output is correct |
11 |
Correct |
63 ms |
4624 KB |
Output is correct |
12 |
Correct |
62 ms |
4432 KB |
Output is correct |
13 |
Correct |
63 ms |
4432 KB |
Output is correct |
14 |
Correct |
63 ms |
4616 KB |
Output is correct |
15 |
Correct |
64 ms |
4640 KB |
Output is correct |
16 |
Correct |
65 ms |
4436 KB |
Output is correct |
17 |
Correct |
63 ms |
4640 KB |
Output is correct |
18 |
Correct |
67 ms |
4452 KB |
Output is correct |
19 |
Correct |
66 ms |
4512 KB |
Output is correct |
20 |
Correct |
72 ms |
4412 KB |
Output is correct |
21 |
Incorrect |
61 ms |
4432 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4436 KB |
Output is correct |
2 |
Correct |
70 ms |
4432 KB |
Output is correct |
3 |
Correct |
70 ms |
4432 KB |
Output is correct |
4 |
Correct |
60 ms |
4380 KB |
Output is correct |
5 |
Correct |
58 ms |
4452 KB |
Output is correct |
6 |
Correct |
58 ms |
4436 KB |
Output is correct |
7 |
Correct |
60 ms |
4444 KB |
Output is correct |
8 |
Correct |
62 ms |
4808 KB |
Output is correct |
9 |
Correct |
62 ms |
4440 KB |
Output is correct |
10 |
Correct |
62 ms |
4596 KB |
Output is correct |
11 |
Correct |
63 ms |
4624 KB |
Output is correct |
12 |
Correct |
62 ms |
4432 KB |
Output is correct |
13 |
Correct |
63 ms |
4432 KB |
Output is correct |
14 |
Correct |
63 ms |
4616 KB |
Output is correct |
15 |
Correct |
64 ms |
4640 KB |
Output is correct |
16 |
Correct |
65 ms |
4436 KB |
Output is correct |
17 |
Correct |
63 ms |
4640 KB |
Output is correct |
18 |
Correct |
67 ms |
4452 KB |
Output is correct |
19 |
Correct |
207 ms |
39164 KB |
Output is correct |
20 |
Correct |
202 ms |
39028 KB |
Output is correct |
21 |
Correct |
132 ms |
37268 KB |
Output is correct |
22 |
Correct |
132 ms |
33892 KB |
Output is correct |
23 |
Correct |
95 ms |
7104 KB |
Output is correct |
24 |
Correct |
99 ms |
6996 KB |
Output is correct |
25 |
Correct |
138 ms |
39224 KB |
Output is correct |
26 |
Correct |
144 ms |
39188 KB |
Output is correct |
27 |
Correct |
155 ms |
39024 KB |
Output is correct |
28 |
Correct |
169 ms |
39036 KB |
Output is correct |
29 |
Correct |
148 ms |
38216 KB |
Output is correct |
30 |
Correct |
105 ms |
7252 KB |
Output is correct |
31 |
Correct |
152 ms |
39040 KB |
Output is correct |
32 |
Correct |
190 ms |
36112 KB |
Output is correct |
33 |
Correct |
96 ms |
6996 KB |
Output is correct |
34 |
Correct |
161 ms |
39208 KB |
Output is correct |
35 |
Correct |
130 ms |
30236 KB |
Output is correct |
36 |
Correct |
96 ms |
6996 KB |
Output is correct |
37 |
Correct |
105 ms |
7112 KB |
Output is correct |
38 |
Correct |
183 ms |
38956 KB |
Output is correct |
39 |
Correct |
109 ms |
39152 KB |
Output is correct |
40 |
Correct |
158 ms |
27524 KB |
Output is correct |
41 |
Correct |
223 ms |
39392 KB |
Output is correct |
42 |
Correct |
52 ms |
38704 KB |
Output is correct |
43 |
Correct |
66 ms |
4512 KB |
Output is correct |
44 |
Correct |
72 ms |
4412 KB |
Output is correct |
45 |
Incorrect |
61 ms |
4432 KB |
Output isn't correct |
46 |
Halted |
0 ms |
0 KB |
- |