/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = (int) 2e5;
int N;
int convert (char c) {
if (c == 'J') {
return 0;
} else if (c == 'O') {
return 1;
} else {
return 2;
}
}
void read (int V[]) {
string str;
cin >> str;
for (int i = 0; i < N; i++) {
V[i] = convert(str[i]);
}
}
int Sinit[3][N_MAX];
int S[9][N_MAX];
int Q;
int T[N_MAX];
struct SGTNode {
int fullS[9];
int fullT;
bool match[9];
};
SGTNode operator + (const SGTNode &u, const SGTNode &v) {
SGTNode w;
for (int k = 0; k < 9; k++) {
w.fullS[k] = (u.fullS[k] == v.fullS[k] ? u.fullS[k] : -1);
w.match[k] = (u.match[k] & v.match[k]);
}
w.fullT = -1;
return w;
}
void setT (SGTNode &u, const int &value) {
u.fullT = value;
for (int k = 0; k < 9; k++) {
u.match[k] = (u.fullS[k] == u.fullT);
}
}
SGTNode SGT[N_MAX * 4 + 2];
void build (int node, int l, int r) {
if (l == r) {
for (int k = 0; k < 9; k++) {
SGT[node].fullS[k] = S[k][l];
}
setT(SGT[node], T[l]);
return;
}
int mid = (l + r) / 2;
int lSon = node * 2, rSon = node * 2 + 1;
build(lSon, l, mid);
build(rSon, mid + 1, r);
SGT[node] = SGT[lSon] + SGT[rSon];
}
void build () {
build(1, 0, N - 1);
}
void split (int node) {
if (SGT[node].fullT == -1) {
return;
}
int lSon = node * 2, rSon = node * 2 + 1;
setT(SGT[lSon], SGT[node].fullT);
setT(SGT[rSon], SGT[node].fullT);
SGT[node].fullT = -1;
}
void update (int node, int l, int r, int ul, int ur, int uval) {
if (ul <= l && r <= ur) {
setT(SGT[node], uval);
return;
}
split(node);
int mid = (l + r) / 2;
int lSon = node * 2, rSon = node * 2 + 1;
if (ul <= mid) {
update(lSon, l, mid, ul, ur, uval);
}
if (mid + 1 <= ur) {
update(rSon, mid + 1, r, ul, ur, uval);
}
SGT[node] = SGT[lSon] + SGT[rSon];
}
void update (int ul, int ur, int uval) {
update(1, 0, N - 1, ul, ur, uval);
}
bool query () {
for (int k = 0; k < 9; k++) {
if (SGT[1].match[k] == true) {
return true;
}
}
return false;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int k = 0; k < 3; k++) {
read(Sinit[k]);
}
{
int curr = 0;
int coef[3];
for (coef[0] = 0; coef[0] < 3; coef[0]++) {
for (coef[1] = 0; coef[1] < 3; coef[1]++) {
for (coef[2] = 0; coef[2] < 3; coef[2]++) {
if ((coef[0] + coef[1] + coef[2]) % 3 == 1) {
for (int i = 0; i < N; i++) {
for (int k = 0; k < 3; k++) {
S[curr][i] += Sinit[k][i] * coef[k];
}
S[curr][i] %= 3;
}
curr++;
}
}
}
}
}
cin >> Q;
read(T);
build();
cout << (query() == true ? "Yes" : "No") << "\n";
while (Q--) {
int ul, ur;
char c;
cin >> ul >> ur >> c; ul--; ur--;
int uval = convert(c);
update(ul, ur, uval);
cout << (query() == true ? "Yes" : "No") << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
2288 KB |
Output is correct |
2 |
Correct |
112 ms |
2536 KB |
Output is correct |
3 |
Correct |
116 ms |
2372 KB |
Output is correct |
4 |
Correct |
94 ms |
2448 KB |
Output is correct |
5 |
Correct |
102 ms |
2332 KB |
Output is correct |
6 |
Correct |
90 ms |
2292 KB |
Output is correct |
7 |
Correct |
94 ms |
2400 KB |
Output is correct |
8 |
Correct |
105 ms |
2416 KB |
Output is correct |
9 |
Correct |
96 ms |
2480 KB |
Output is correct |
10 |
Correct |
94 ms |
2500 KB |
Output is correct |
11 |
Correct |
99 ms |
2500 KB |
Output is correct |
12 |
Correct |
110 ms |
2524 KB |
Output is correct |
13 |
Correct |
99 ms |
2460 KB |
Output is correct |
14 |
Correct |
99 ms |
2456 KB |
Output is correct |
15 |
Correct |
97 ms |
2424 KB |
Output is correct |
16 |
Correct |
96 ms |
2500 KB |
Output is correct |
17 |
Correct |
95 ms |
2516 KB |
Output is correct |
18 |
Correct |
120 ms |
2564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
2288 KB |
Output is correct |
2 |
Correct |
112 ms |
2536 KB |
Output is correct |
3 |
Correct |
116 ms |
2372 KB |
Output is correct |
4 |
Correct |
94 ms |
2448 KB |
Output is correct |
5 |
Correct |
102 ms |
2332 KB |
Output is correct |
6 |
Correct |
90 ms |
2292 KB |
Output is correct |
7 |
Correct |
94 ms |
2400 KB |
Output is correct |
8 |
Correct |
105 ms |
2416 KB |
Output is correct |
9 |
Correct |
96 ms |
2480 KB |
Output is correct |
10 |
Correct |
94 ms |
2500 KB |
Output is correct |
11 |
Correct |
99 ms |
2500 KB |
Output is correct |
12 |
Correct |
110 ms |
2524 KB |
Output is correct |
13 |
Correct |
99 ms |
2460 KB |
Output is correct |
14 |
Correct |
99 ms |
2456 KB |
Output is correct |
15 |
Correct |
97 ms |
2424 KB |
Output is correct |
16 |
Correct |
96 ms |
2500 KB |
Output is correct |
17 |
Correct |
95 ms |
2516 KB |
Output is correct |
18 |
Correct |
120 ms |
2564 KB |
Output is correct |
19 |
Correct |
398 ms |
41868 KB |
Output is correct |
20 |
Correct |
410 ms |
41748 KB |
Output is correct |
21 |
Correct |
264 ms |
40988 KB |
Output is correct |
22 |
Correct |
249 ms |
39852 KB |
Output is correct |
23 |
Correct |
157 ms |
5552 KB |
Output is correct |
24 |
Correct |
171 ms |
5568 KB |
Output is correct |
25 |
Correct |
263 ms |
41880 KB |
Output is correct |
26 |
Correct |
279 ms |
41896 KB |
Output is correct |
27 |
Correct |
310 ms |
41768 KB |
Output is correct |
28 |
Correct |
314 ms |
41796 KB |
Output is correct |
29 |
Correct |
320 ms |
41528 KB |
Output is correct |
30 |
Correct |
180 ms |
5504 KB |
Output is correct |
31 |
Correct |
330 ms |
41800 KB |
Output is correct |
32 |
Correct |
314 ms |
40644 KB |
Output is correct |
33 |
Correct |
175 ms |
5508 KB |
Output is correct |
34 |
Correct |
317 ms |
42084 KB |
Output is correct |
35 |
Correct |
238 ms |
38744 KB |
Output is correct |
36 |
Correct |
179 ms |
5540 KB |
Output is correct |
37 |
Correct |
163 ms |
5476 KB |
Output is correct |
38 |
Correct |
351 ms |
41640 KB |
Output is correct |
39 |
Correct |
210 ms |
42064 KB |
Output is correct |
40 |
Correct |
242 ms |
24520 KB |
Output is correct |
41 |
Correct |
460 ms |
42296 KB |
Output is correct |
42 |
Correct |
68 ms |
41308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
2288 KB |
Output is correct |
2 |
Correct |
112 ms |
2536 KB |
Output is correct |
3 |
Correct |
116 ms |
2372 KB |
Output is correct |
4 |
Correct |
94 ms |
2448 KB |
Output is correct |
5 |
Correct |
102 ms |
2332 KB |
Output is correct |
6 |
Correct |
90 ms |
2292 KB |
Output is correct |
7 |
Correct |
94 ms |
2400 KB |
Output is correct |
8 |
Correct |
105 ms |
2416 KB |
Output is correct |
9 |
Correct |
96 ms |
2480 KB |
Output is correct |
10 |
Correct |
94 ms |
2500 KB |
Output is correct |
11 |
Correct |
99 ms |
2500 KB |
Output is correct |
12 |
Correct |
110 ms |
2524 KB |
Output is correct |
13 |
Correct |
99 ms |
2460 KB |
Output is correct |
14 |
Correct |
99 ms |
2456 KB |
Output is correct |
15 |
Correct |
97 ms |
2424 KB |
Output is correct |
16 |
Correct |
96 ms |
2500 KB |
Output is correct |
17 |
Correct |
95 ms |
2516 KB |
Output is correct |
18 |
Correct |
120 ms |
2564 KB |
Output is correct |
19 |
Correct |
110 ms |
2356 KB |
Output is correct |
20 |
Correct |
117 ms |
2336 KB |
Output is correct |
21 |
Correct |
108 ms |
2416 KB |
Output is correct |
22 |
Correct |
84 ms |
2320 KB |
Output is correct |
23 |
Correct |
97 ms |
2500 KB |
Output is correct |
24 |
Correct |
95 ms |
2352 KB |
Output is correct |
25 |
Correct |
97 ms |
2500 KB |
Output is correct |
26 |
Correct |
88 ms |
2400 KB |
Output is correct |
27 |
Correct |
98 ms |
2500 KB |
Output is correct |
28 |
Correct |
88 ms |
2324 KB |
Output is correct |
29 |
Correct |
97 ms |
2472 KB |
Output is correct |
30 |
Correct |
88 ms |
2276 KB |
Output is correct |
31 |
Correct |
100 ms |
2412 KB |
Output is correct |
32 |
Correct |
102 ms |
2500 KB |
Output is correct |
33 |
Correct |
103 ms |
2492 KB |
Output is correct |
34 |
Correct |
96 ms |
2328 KB |
Output is correct |
35 |
Correct |
104 ms |
2532 KB |
Output is correct |
36 |
Correct |
100 ms |
2536 KB |
Output is correct |
37 |
Correct |
113 ms |
2492 KB |
Output is correct |
38 |
Correct |
109 ms |
2524 KB |
Output is correct |
39 |
Correct |
107 ms |
2488 KB |
Output is correct |
40 |
Correct |
103 ms |
2532 KB |
Output is correct |
41 |
Correct |
105 ms |
2520 KB |
Output is correct |
42 |
Correct |
107 ms |
2504 KB |
Output is correct |
43 |
Correct |
119 ms |
2476 KB |
Output is correct |
44 |
Correct |
101 ms |
2468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
2288 KB |
Output is correct |
2 |
Correct |
112 ms |
2536 KB |
Output is correct |
3 |
Correct |
116 ms |
2372 KB |
Output is correct |
4 |
Correct |
94 ms |
2448 KB |
Output is correct |
5 |
Correct |
102 ms |
2332 KB |
Output is correct |
6 |
Correct |
90 ms |
2292 KB |
Output is correct |
7 |
Correct |
94 ms |
2400 KB |
Output is correct |
8 |
Correct |
105 ms |
2416 KB |
Output is correct |
9 |
Correct |
96 ms |
2480 KB |
Output is correct |
10 |
Correct |
94 ms |
2500 KB |
Output is correct |
11 |
Correct |
99 ms |
2500 KB |
Output is correct |
12 |
Correct |
110 ms |
2524 KB |
Output is correct |
13 |
Correct |
99 ms |
2460 KB |
Output is correct |
14 |
Correct |
99 ms |
2456 KB |
Output is correct |
15 |
Correct |
97 ms |
2424 KB |
Output is correct |
16 |
Correct |
96 ms |
2500 KB |
Output is correct |
17 |
Correct |
95 ms |
2516 KB |
Output is correct |
18 |
Correct |
120 ms |
2564 KB |
Output is correct |
19 |
Correct |
398 ms |
41868 KB |
Output is correct |
20 |
Correct |
410 ms |
41748 KB |
Output is correct |
21 |
Correct |
264 ms |
40988 KB |
Output is correct |
22 |
Correct |
249 ms |
39852 KB |
Output is correct |
23 |
Correct |
157 ms |
5552 KB |
Output is correct |
24 |
Correct |
171 ms |
5568 KB |
Output is correct |
25 |
Correct |
263 ms |
41880 KB |
Output is correct |
26 |
Correct |
279 ms |
41896 KB |
Output is correct |
27 |
Correct |
310 ms |
41768 KB |
Output is correct |
28 |
Correct |
314 ms |
41796 KB |
Output is correct |
29 |
Correct |
320 ms |
41528 KB |
Output is correct |
30 |
Correct |
180 ms |
5504 KB |
Output is correct |
31 |
Correct |
330 ms |
41800 KB |
Output is correct |
32 |
Correct |
314 ms |
40644 KB |
Output is correct |
33 |
Correct |
175 ms |
5508 KB |
Output is correct |
34 |
Correct |
317 ms |
42084 KB |
Output is correct |
35 |
Correct |
238 ms |
38744 KB |
Output is correct |
36 |
Correct |
179 ms |
5540 KB |
Output is correct |
37 |
Correct |
163 ms |
5476 KB |
Output is correct |
38 |
Correct |
351 ms |
41640 KB |
Output is correct |
39 |
Correct |
210 ms |
42064 KB |
Output is correct |
40 |
Correct |
242 ms |
24520 KB |
Output is correct |
41 |
Correct |
460 ms |
42296 KB |
Output is correct |
42 |
Correct |
68 ms |
41308 KB |
Output is correct |
43 |
Correct |
110 ms |
2356 KB |
Output is correct |
44 |
Correct |
117 ms |
2336 KB |
Output is correct |
45 |
Correct |
108 ms |
2416 KB |
Output is correct |
46 |
Correct |
84 ms |
2320 KB |
Output is correct |
47 |
Correct |
97 ms |
2500 KB |
Output is correct |
48 |
Correct |
95 ms |
2352 KB |
Output is correct |
49 |
Correct |
97 ms |
2500 KB |
Output is correct |
50 |
Correct |
88 ms |
2400 KB |
Output is correct |
51 |
Correct |
98 ms |
2500 KB |
Output is correct |
52 |
Correct |
88 ms |
2324 KB |
Output is correct |
53 |
Correct |
97 ms |
2472 KB |
Output is correct |
54 |
Correct |
88 ms |
2276 KB |
Output is correct |
55 |
Correct |
100 ms |
2412 KB |
Output is correct |
56 |
Correct |
102 ms |
2500 KB |
Output is correct |
57 |
Correct |
103 ms |
2492 KB |
Output is correct |
58 |
Correct |
96 ms |
2328 KB |
Output is correct |
59 |
Correct |
104 ms |
2532 KB |
Output is correct |
60 |
Correct |
100 ms |
2536 KB |
Output is correct |
61 |
Correct |
113 ms |
2492 KB |
Output is correct |
62 |
Correct |
109 ms |
2524 KB |
Output is correct |
63 |
Correct |
107 ms |
2488 KB |
Output is correct |
64 |
Correct |
103 ms |
2532 KB |
Output is correct |
65 |
Correct |
105 ms |
2520 KB |
Output is correct |
66 |
Correct |
107 ms |
2504 KB |
Output is correct |
67 |
Correct |
119 ms |
2476 KB |
Output is correct |
68 |
Correct |
101 ms |
2468 KB |
Output is correct |
69 |
Correct |
427 ms |
39764 KB |
Output is correct |
70 |
Correct |
450 ms |
41676 KB |
Output is correct |
71 |
Correct |
170 ms |
5512 KB |
Output is correct |
72 |
Correct |
192 ms |
5460 KB |
Output is correct |
73 |
Correct |
165 ms |
5480 KB |
Output is correct |
74 |
Correct |
272 ms |
39720 KB |
Output is correct |
75 |
Correct |
189 ms |
5412 KB |
Output is correct |
76 |
Correct |
274 ms |
41780 KB |
Output is correct |
77 |
Correct |
272 ms |
39812 KB |
Output is correct |
78 |
Correct |
170 ms |
5444 KB |
Output is correct |
79 |
Correct |
185 ms |
5468 KB |
Output is correct |
80 |
Correct |
336 ms |
38068 KB |
Output is correct |
81 |
Correct |
192 ms |
5460 KB |
Output is correct |
82 |
Correct |
342 ms |
41788 KB |
Output is correct |
83 |
Correct |
285 ms |
40888 KB |
Output is correct |
84 |
Correct |
177 ms |
5428 KB |
Output is correct |
85 |
Correct |
188 ms |
5504 KB |
Output is correct |
86 |
Correct |
360 ms |
38868 KB |
Output is correct |
87 |
Correct |
382 ms |
41864 KB |
Output is correct |
88 |
Correct |
201 ms |
5464 KB |
Output is correct |
89 |
Correct |
306 ms |
40272 KB |
Output is correct |
90 |
Correct |
324 ms |
41860 KB |
Output is correct |
91 |
Correct |
198 ms |
5528 KB |
Output is correct |
92 |
Correct |
247 ms |
38696 KB |
Output is correct |
93 |
Correct |
171 ms |
5412 KB |
Output is correct |
94 |
Correct |
172 ms |
5444 KB |
Output is correct |
95 |
Correct |
173 ms |
5492 KB |
Output is correct |
96 |
Correct |
321 ms |
41640 KB |
Output is correct |
97 |
Correct |
206 ms |
41896 KB |
Output is correct |
98 |
Correct |
254 ms |
24400 KB |
Output is correct |
99 |
Correct |
443 ms |
42012 KB |
Output is correct |
100 |
Correct |
69 ms |
41304 KB |
Output is correct |