#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
struct SGT {
struct node {
array<int, 3> count = {0, 0, 0};
int bd_count = 0;
int d = -1;
node() {}
node(int a, int b) {
count[b] = 1;
d = a;
if (a == b) {
bd_count = 0;
} else {
bd_count = 1;
}
}
void apply(int a) {
d = a;
bd_count = count[0] + count[1] + count[2] - count[a];
}
};
void merge(const node &a, const node &b, node &c) {
c.d = -1;
c.count[0] = a.count[0] + b.count[0];
c.count[1] = a.count[1] + b.count[1];
c.count[2] = a.count[2] + b.count[2];
c.bd_count = a.bd_count + b.bd_count;
}
int n;
vector<node> t;
void push(int v) {
if (t[v].d != -1) {
t[v + v].apply(t[v].d);
t[v + v + 1].apply(t[v].d);
t[v].d = -1;
}
}
void upd(int v) {
merge(t[v + v], t[v + v + 1], t[v]);
}
void build(int v, int tl, int tr, vector<int> &a, vector<int> &b) {
if (tl == tr) {
t[v] = node(a[tl], b[tl]);
return;
}
int tm = (tl + tr) / 2;
build(v + v, tl, tm, a, b);
build(v + v + 1, tm + 1, tr, a, b);
upd(v);
}
void build(vector<int> &a, vector<int> &b) {
n = a.size();
t.resize(n * 4);
build(1, 0, n - 1, a, b);
}
void chng(int v, int tl, int tr, int l, int r, int x) {
if (tr < l || r < tl) {
return;
}
if (l <= tl && tr <= r) {
t[v].apply(x);
return;
}
push(v);
int tm = (tl + tr) / 2;
chng(v + v, tl, tm, l, r, x);
chng(v + v + 1, tm + 1, tr, l, r, x);
upd(v);
}
void chng(int l, int r, int x) {
chng(1, 0, n - 1, l, r, x);
}
bool get() {
return t[1].bd_count == 0;
}
};
int n;
vector<vector<int>> x;
vector<vector<int>> gd;
int gd_sz;
vector<SGT> sgt;
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n;
x.assign(3, vector<int>(n));
for (int i = 0; i < 3; i += 1) {
for (int j = 0; j < n; j += 1) {
char c;
cin >> c;
if (c == 'J') {
x[i][j] = 0;
} else if (c == 'O') {
x[i][j] = 1;
} else if (c == 'I') {
x[i][j] = 2;
}
}
}
gd.clear();
for (int c0 = 0; c0 < 3; c0 += 1) {
for (int c1 = 0; c1 < 3; c1 += 1) {
int c2 = (1 + 2 * c0 + 2 * c1) % 3;
assert((c0 + c1 + c2) % 3 == 1);
vector<int> t(n);
for (int i = 0; i < n; i += 1) {
t[i] = (x[0][i] * c0 + x[1][i] * c1 + x[2][i] * c2) % 3;
}
gd.push_back(t);
}
}
gd_sz = gd.size();
int q;
cin >> q;
vector<int> t0(n);
for (int i = 0; i < n; i += 1) {
char c;
cin >> c;
if (c == 'J') {
t0[i] = 0;
} else if (c == 'O') {
t0[i] = 1;
} else if (c == 'I') {
t0[i] = 2;
}
}
sgt.resize(gd_sz);
for (int i = 0; i < gd_sz; i += 1) {
sgt[i].build(t0, gd[i]);
}
for (int i = 0; i <= q; i += 1) {
bool ok = false;
for (int j = 0; j < gd_sz; j += 1) {
if (sgt[j].get()) {
ok = true;
break;
}
}
if (ok) {
cout << "Yes"
<< "\n";
} else {
cout << "No"
<< "\n";
}
if(i == q){
break;
}
int l, r;
char c;
cin >> l >> r >> c;
--l;
--r;
int aboba;
if (c == 'J') {
aboba = 0;
} else if (c == 'O') {
aboba = 1;
} else if (c == 'I') {
aboba = 2;
}
for(int j = 0; j < gd_sz; j += 1){
sgt[j].chng(l, r, aboba);
}
}
return 0;
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:28:15: warning: 'aboba' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | d = a;
| ~~^~~
Main.cpp:178:13: note: 'aboba' was declared here
178 | int aboba;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
2216 KB |
Output is correct |
2 |
Correct |
210 ms |
2480 KB |
Output is correct |
3 |
Correct |
230 ms |
2380 KB |
Output is correct |
4 |
Correct |
165 ms |
2324 KB |
Output is correct |
5 |
Correct |
208 ms |
2360 KB |
Output is correct |
6 |
Correct |
177 ms |
2296 KB |
Output is correct |
7 |
Correct |
165 ms |
2344 KB |
Output is correct |
8 |
Correct |
180 ms |
2460 KB |
Output is correct |
9 |
Correct |
191 ms |
2460 KB |
Output is correct |
10 |
Correct |
177 ms |
2432 KB |
Output is correct |
11 |
Correct |
195 ms |
2488 KB |
Output is correct |
12 |
Correct |
182 ms |
2540 KB |
Output is correct |
13 |
Correct |
180 ms |
2412 KB |
Output is correct |
14 |
Correct |
176 ms |
2440 KB |
Output is correct |
15 |
Correct |
180 ms |
2472 KB |
Output is correct |
16 |
Correct |
177 ms |
2400 KB |
Output is correct |
17 |
Correct |
180 ms |
2408 KB |
Output is correct |
18 |
Correct |
195 ms |
2380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
2216 KB |
Output is correct |
2 |
Correct |
210 ms |
2480 KB |
Output is correct |
3 |
Correct |
230 ms |
2380 KB |
Output is correct |
4 |
Correct |
165 ms |
2324 KB |
Output is correct |
5 |
Correct |
208 ms |
2360 KB |
Output is correct |
6 |
Correct |
177 ms |
2296 KB |
Output is correct |
7 |
Correct |
165 ms |
2344 KB |
Output is correct |
8 |
Correct |
180 ms |
2460 KB |
Output is correct |
9 |
Correct |
191 ms |
2460 KB |
Output is correct |
10 |
Correct |
177 ms |
2432 KB |
Output is correct |
11 |
Correct |
195 ms |
2488 KB |
Output is correct |
12 |
Correct |
182 ms |
2540 KB |
Output is correct |
13 |
Correct |
180 ms |
2412 KB |
Output is correct |
14 |
Correct |
176 ms |
2440 KB |
Output is correct |
15 |
Correct |
180 ms |
2472 KB |
Output is correct |
16 |
Correct |
177 ms |
2400 KB |
Output is correct |
17 |
Correct |
180 ms |
2408 KB |
Output is correct |
18 |
Correct |
195 ms |
2380 KB |
Output is correct |
19 |
Correct |
1404 ms |
155672 KB |
Output is correct |
20 |
Correct |
1142 ms |
155596 KB |
Output is correct |
21 |
Correct |
893 ms |
146460 KB |
Output is correct |
22 |
Correct |
884 ms |
131664 KB |
Output is correct |
23 |
Correct |
403 ms |
11180 KB |
Output is correct |
24 |
Correct |
356 ms |
10832 KB |
Output is correct |
25 |
Correct |
1014 ms |
155660 KB |
Output is correct |
26 |
Correct |
984 ms |
155716 KB |
Output is correct |
27 |
Correct |
1233 ms |
155648 KB |
Output is correct |
28 |
Correct |
1297 ms |
155672 KB |
Output is correct |
29 |
Correct |
1131 ms |
151220 KB |
Output is correct |
30 |
Correct |
425 ms |
11076 KB |
Output is correct |
31 |
Correct |
1110 ms |
155640 KB |
Output is correct |
32 |
Correct |
1109 ms |
142316 KB |
Output is correct |
33 |
Correct |
368 ms |
10788 KB |
Output is correct |
34 |
Correct |
1168 ms |
155652 KB |
Output is correct |
35 |
Correct |
883 ms |
116548 KB |
Output is correct |
36 |
Correct |
368 ms |
10756 KB |
Output is correct |
37 |
Correct |
406 ms |
10800 KB |
Output is correct |
38 |
Correct |
1012 ms |
155416 KB |
Output is correct |
39 |
Correct |
617 ms |
155716 KB |
Output is correct |
40 |
Correct |
932 ms |
103284 KB |
Output is correct |
41 |
Correct |
1712 ms |
155824 KB |
Output is correct |
42 |
Correct |
133 ms |
155112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
2216 KB |
Output is correct |
2 |
Correct |
210 ms |
2480 KB |
Output is correct |
3 |
Correct |
230 ms |
2380 KB |
Output is correct |
4 |
Correct |
165 ms |
2324 KB |
Output is correct |
5 |
Correct |
208 ms |
2360 KB |
Output is correct |
6 |
Correct |
177 ms |
2296 KB |
Output is correct |
7 |
Correct |
165 ms |
2344 KB |
Output is correct |
8 |
Correct |
180 ms |
2460 KB |
Output is correct |
9 |
Correct |
191 ms |
2460 KB |
Output is correct |
10 |
Correct |
177 ms |
2432 KB |
Output is correct |
11 |
Correct |
195 ms |
2488 KB |
Output is correct |
12 |
Correct |
182 ms |
2540 KB |
Output is correct |
13 |
Correct |
180 ms |
2412 KB |
Output is correct |
14 |
Correct |
176 ms |
2440 KB |
Output is correct |
15 |
Correct |
180 ms |
2472 KB |
Output is correct |
16 |
Correct |
177 ms |
2400 KB |
Output is correct |
17 |
Correct |
180 ms |
2408 KB |
Output is correct |
18 |
Correct |
195 ms |
2380 KB |
Output is correct |
19 |
Correct |
202 ms |
2368 KB |
Output is correct |
20 |
Correct |
232 ms |
2356 KB |
Output is correct |
21 |
Correct |
228 ms |
2416 KB |
Output is correct |
22 |
Correct |
149 ms |
2252 KB |
Output is correct |
23 |
Correct |
195 ms |
2520 KB |
Output is correct |
24 |
Correct |
172 ms |
2420 KB |
Output is correct |
25 |
Correct |
181 ms |
2392 KB |
Output is correct |
26 |
Correct |
162 ms |
2456 KB |
Output is correct |
27 |
Correct |
178 ms |
2404 KB |
Output is correct |
28 |
Correct |
162 ms |
2196 KB |
Output is correct |
29 |
Correct |
205 ms |
2460 KB |
Output is correct |
30 |
Correct |
155 ms |
2272 KB |
Output is correct |
31 |
Correct |
177 ms |
2456 KB |
Output is correct |
32 |
Correct |
207 ms |
2364 KB |
Output is correct |
33 |
Correct |
183 ms |
2520 KB |
Output is correct |
34 |
Correct |
155 ms |
2324 KB |
Output is correct |
35 |
Correct |
181 ms |
2504 KB |
Output is correct |
36 |
Correct |
206 ms |
2420 KB |
Output is correct |
37 |
Correct |
178 ms |
2488 KB |
Output is correct |
38 |
Correct |
184 ms |
2508 KB |
Output is correct |
39 |
Correct |
178 ms |
2512 KB |
Output is correct |
40 |
Correct |
181 ms |
2480 KB |
Output is correct |
41 |
Correct |
186 ms |
2456 KB |
Output is correct |
42 |
Correct |
192 ms |
2432 KB |
Output is correct |
43 |
Correct |
177 ms |
2376 KB |
Output is correct |
44 |
Correct |
179 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
2216 KB |
Output is correct |
2 |
Correct |
210 ms |
2480 KB |
Output is correct |
3 |
Correct |
230 ms |
2380 KB |
Output is correct |
4 |
Correct |
165 ms |
2324 KB |
Output is correct |
5 |
Correct |
208 ms |
2360 KB |
Output is correct |
6 |
Correct |
177 ms |
2296 KB |
Output is correct |
7 |
Correct |
165 ms |
2344 KB |
Output is correct |
8 |
Correct |
180 ms |
2460 KB |
Output is correct |
9 |
Correct |
191 ms |
2460 KB |
Output is correct |
10 |
Correct |
177 ms |
2432 KB |
Output is correct |
11 |
Correct |
195 ms |
2488 KB |
Output is correct |
12 |
Correct |
182 ms |
2540 KB |
Output is correct |
13 |
Correct |
180 ms |
2412 KB |
Output is correct |
14 |
Correct |
176 ms |
2440 KB |
Output is correct |
15 |
Correct |
180 ms |
2472 KB |
Output is correct |
16 |
Correct |
177 ms |
2400 KB |
Output is correct |
17 |
Correct |
180 ms |
2408 KB |
Output is correct |
18 |
Correct |
195 ms |
2380 KB |
Output is correct |
19 |
Correct |
1404 ms |
155672 KB |
Output is correct |
20 |
Correct |
1142 ms |
155596 KB |
Output is correct |
21 |
Correct |
893 ms |
146460 KB |
Output is correct |
22 |
Correct |
884 ms |
131664 KB |
Output is correct |
23 |
Correct |
403 ms |
11180 KB |
Output is correct |
24 |
Correct |
356 ms |
10832 KB |
Output is correct |
25 |
Correct |
1014 ms |
155660 KB |
Output is correct |
26 |
Correct |
984 ms |
155716 KB |
Output is correct |
27 |
Correct |
1233 ms |
155648 KB |
Output is correct |
28 |
Correct |
1297 ms |
155672 KB |
Output is correct |
29 |
Correct |
1131 ms |
151220 KB |
Output is correct |
30 |
Correct |
425 ms |
11076 KB |
Output is correct |
31 |
Correct |
1110 ms |
155640 KB |
Output is correct |
32 |
Correct |
1109 ms |
142316 KB |
Output is correct |
33 |
Correct |
368 ms |
10788 KB |
Output is correct |
34 |
Correct |
1168 ms |
155652 KB |
Output is correct |
35 |
Correct |
883 ms |
116548 KB |
Output is correct |
36 |
Correct |
368 ms |
10756 KB |
Output is correct |
37 |
Correct |
406 ms |
10800 KB |
Output is correct |
38 |
Correct |
1012 ms |
155416 KB |
Output is correct |
39 |
Correct |
617 ms |
155716 KB |
Output is correct |
40 |
Correct |
932 ms |
103284 KB |
Output is correct |
41 |
Correct |
1712 ms |
155824 KB |
Output is correct |
42 |
Correct |
133 ms |
155112 KB |
Output is correct |
43 |
Correct |
202 ms |
2368 KB |
Output is correct |
44 |
Correct |
232 ms |
2356 KB |
Output is correct |
45 |
Correct |
228 ms |
2416 KB |
Output is correct |
46 |
Correct |
149 ms |
2252 KB |
Output is correct |
47 |
Correct |
195 ms |
2520 KB |
Output is correct |
48 |
Correct |
172 ms |
2420 KB |
Output is correct |
49 |
Correct |
181 ms |
2392 KB |
Output is correct |
50 |
Correct |
162 ms |
2456 KB |
Output is correct |
51 |
Correct |
178 ms |
2404 KB |
Output is correct |
52 |
Correct |
162 ms |
2196 KB |
Output is correct |
53 |
Correct |
205 ms |
2460 KB |
Output is correct |
54 |
Correct |
155 ms |
2272 KB |
Output is correct |
55 |
Correct |
177 ms |
2456 KB |
Output is correct |
56 |
Correct |
207 ms |
2364 KB |
Output is correct |
57 |
Correct |
183 ms |
2520 KB |
Output is correct |
58 |
Correct |
155 ms |
2324 KB |
Output is correct |
59 |
Correct |
181 ms |
2504 KB |
Output is correct |
60 |
Correct |
206 ms |
2420 KB |
Output is correct |
61 |
Correct |
178 ms |
2488 KB |
Output is correct |
62 |
Correct |
184 ms |
2508 KB |
Output is correct |
63 |
Correct |
178 ms |
2512 KB |
Output is correct |
64 |
Correct |
181 ms |
2480 KB |
Output is correct |
65 |
Correct |
186 ms |
2456 KB |
Output is correct |
66 |
Correct |
192 ms |
2432 KB |
Output is correct |
67 |
Correct |
177 ms |
2376 KB |
Output is correct |
68 |
Correct |
179 ms |
2508 KB |
Output is correct |
69 |
Correct |
1250 ms |
130464 KB |
Output is correct |
70 |
Correct |
1106 ms |
155724 KB |
Output is correct |
71 |
Correct |
419 ms |
10940 KB |
Output is correct |
72 |
Correct |
367 ms |
11084 KB |
Output is correct |
73 |
Correct |
386 ms |
11244 KB |
Output is correct |
74 |
Correct |
849 ms |
130276 KB |
Output is correct |
75 |
Correct |
406 ms |
10848 KB |
Output is correct |
76 |
Correct |
989 ms |
155680 KB |
Output is correct |
77 |
Correct |
931 ms |
130432 KB |
Output is correct |
78 |
Correct |
447 ms |
10848 KB |
Output is correct |
79 |
Correct |
373 ms |
11016 KB |
Output is correct |
80 |
Correct |
926 ms |
111528 KB |
Output is correct |
81 |
Correct |
367 ms |
10836 KB |
Output is correct |
82 |
Correct |
1113 ms |
155692 KB |
Output is correct |
83 |
Correct |
1077 ms |
146344 KB |
Output is correct |
84 |
Correct |
435 ms |
10876 KB |
Output is correct |
85 |
Correct |
375 ms |
10760 KB |
Output is correct |
86 |
Correct |
1114 ms |
119016 KB |
Output is correct |
87 |
Correct |
1177 ms |
155668 KB |
Output is correct |
88 |
Correct |
410 ms |
10972 KB |
Output is correct |
89 |
Correct |
1084 ms |
137428 KB |
Output is correct |
90 |
Correct |
1197 ms |
155668 KB |
Output is correct |
91 |
Correct |
404 ms |
11020 KB |
Output is correct |
92 |
Correct |
940 ms |
117152 KB |
Output is correct |
93 |
Correct |
367 ms |
10780 KB |
Output is correct |
94 |
Correct |
392 ms |
10868 KB |
Output is correct |
95 |
Correct |
402 ms |
10860 KB |
Output is correct |
96 |
Correct |
971 ms |
155420 KB |
Output is correct |
97 |
Correct |
511 ms |
155788 KB |
Output is correct |
98 |
Correct |
909 ms |
103332 KB |
Output is correct |
99 |
Correct |
1675 ms |
155892 KB |
Output is correct |
100 |
Correct |
139 ms |
155072 KB |
Output is correct |