#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 1000001;
map <vector <int>, bool> used;
vector <vector <int> > vec;
vector <int> op(vector <int> &a, vector <int> &b){
vector <int> ans;
for(int i = 0; i < a.size(); i++){
int x = a[i] + b[i];
x = -x;
x %= 3;
x += 3;
x %= 3;
ans.pb(x);
}
return ans;
}
void rec(vector <int> &v){
used[v] = true;
vec.pb(v);
vector <vector <int> > q;
for(auto to : vec){
vector <int> x = op(to, v);
if(used[x]) continue;
q.push_back(x);
used[x] = true;
}
for(auto to : q)
rec(to);
}
int L[nmax], R[nmax];
int blsize = 501;
bool good[nmax][10];
int val[nmax];
int opt[nmax][10];
vector <int> b;
void update_block(int ind, int v, int bl){
if(opt[bl][ind] == v)
good[bl][ind] = true;
else good[bl][ind] = false;
val[bl] = v;
}
void fil(int bl){
if(val[bl] == -1) return;
for(int i = L[bl]; i <= R[bl]; i++)
b[i] = val[bl];
val[bl] = -1;
}
bool check(int bl, int ind){
for(int i = L[bl]; i <= R[bl]; i++){
if(b[i] != vec[ind][i]) return false;
}
return true;
}
void update_ran(int ind, int l, int r, int v){
int bl = l / blsize;
good[bl][ind] = false;
fil(bl);
for(int i = l; i <= r; i++)
b[i] = v;
good[bl][ind] = check(bl, ind);
}
bool CH(int sz){
bool ans = false;
for(int j = 0; j < vec.size(); j++){
bool cur = true;
for(int i= 0; i <= sz; i++){
cur &= good[i][j];
}
ans |= cur;
}
return ans;
}
int main(){
// ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int cur = 1;
int curbl = 0;
L[0] = 0;
for(int i = 1; i < n; i++){
if(cur + 1 > blsize){
R[curbl] = i - 1;
cur = 1;
L[++curbl] = i;
}
else cur++;
}
R[curbl] = n - 1;
for(int i = 0; i <= curbl ;i++)
val[i] = -1;
string a[3];
for(int i = 0; i < 3; i++){
vector<int> v;
cin >> a[i];
for(int j = 0; j < n; j++){
if(a[i][j] == 'O')
v.pb(0);
if(a[i][j] == 'J')
v.pb(1);
if(a[i][j] == 'I')
v.pb(2);
}
//used[v] = true;
rec(v);
//vec.pb(v);
}
// cout << vec.size() << "\n";
int q; cin >> q;
for(int i = 0; i < n; i++){
char c; cin >> c;
if(c == 'J')
b.pb(1);
if(c == 'O')
b.pb(0);
if(c == 'I')
b.pb(2);
}
// cout << vec.size();
for(int i = 0; i < n; i++){
for(int j = 0; j < vec.size(); j++)
update_ran(j, i, i, b[i]);
}
for(int j = 0; j < vec.size(); j++){
for(int i = 0; i <= curbl; i++){
opt[i][j] = vec[j][L[i]];
for(int x = L[i] + 1; x <= R[i]; x++)
if(vec[j][x] != vec[j][x - 1])
opt[i][j] = -1;
}
}
CH(curbl) ? cout << "Yes\n" : cout << "No\n";
while(q--){
int l,r; cin >> l >> r;
char c; cin >> c;
int x;
if(c == 'O')
x = 0;
if(c == 'J')
x = 1;
if(c == 'I')
x = 2;
l--, r--;
int X = l / blsize;
int Y = r / blsize;
if(X == Y){
for(int j = 0; j < vec.size(); j++)
update_ran(j, l, r, x);
}
else{
for(int i = X + 1; i < Y; i++){
for(int j = 0; j < vec.size(); j++)
update_block(j, x, i);
}
for(int j = 0; j < vec.size(); j++){
update_ran(j, l, R[X], x);
update_ran(j, L[Y], r, x);
}
}
CH(curbl) ? cout << "Yes\n" : cout << "No\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'std::vector<int> op(std::vector<int>&, std::vector<int>&)':
Main.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
Main.cpp: In function 'bool CH(int)':
Main.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int j = 0; j < vec.size(); j++){
| ~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:141:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for(int j = 0; j < vec.size(); j++)
| ~~^~~~~~~~~~~~
Main.cpp:144:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
144 | for(int j = 0; j < vec.size(); j++){
| ~~^~~~~~~~~~~~
Main.cpp:167:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
167 | for(int j = 0; j < vec.size(); j++)
| ~~^~~~~~~~~~~~
Main.cpp:172:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
172 | for(int j = 0; j < vec.size(); j++)
| ~~^~~~~~~~~~~~
Main.cpp:175:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
175 | for(int j = 0; j < vec.size(); j++){
| ~~^~~~~~~~~~~~
Main.cpp:53:5: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | if(opt[bl][ind] == v)
| ^~
Main.cpp:156:13: note: 'x' was declared here
156 | int x;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
852 KB |
Output is correct |
2 |
Correct |
381 ms |
908 KB |
Output is correct |
3 |
Correct |
412 ms |
880 KB |
Output is correct |
4 |
Correct |
352 ms |
944 KB |
Output is correct |
5 |
Correct |
352 ms |
912 KB |
Output is correct |
6 |
Correct |
354 ms |
824 KB |
Output is correct |
7 |
Correct |
348 ms |
920 KB |
Output is correct |
8 |
Correct |
364 ms |
900 KB |
Output is correct |
9 |
Correct |
340 ms |
844 KB |
Output is correct |
10 |
Correct |
349 ms |
836 KB |
Output is correct |
11 |
Correct |
336 ms |
884 KB |
Output is correct |
12 |
Correct |
336 ms |
892 KB |
Output is correct |
13 |
Correct |
333 ms |
896 KB |
Output is correct |
14 |
Correct |
336 ms |
908 KB |
Output is correct |
15 |
Correct |
351 ms |
1016 KB |
Output is correct |
16 |
Correct |
366 ms |
904 KB |
Output is correct |
17 |
Correct |
340 ms |
860 KB |
Output is correct |
18 |
Correct |
397 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
852 KB |
Output is correct |
2 |
Correct |
381 ms |
908 KB |
Output is correct |
3 |
Correct |
412 ms |
880 KB |
Output is correct |
4 |
Correct |
352 ms |
944 KB |
Output is correct |
5 |
Correct |
352 ms |
912 KB |
Output is correct |
6 |
Correct |
354 ms |
824 KB |
Output is correct |
7 |
Correct |
348 ms |
920 KB |
Output is correct |
8 |
Correct |
364 ms |
900 KB |
Output is correct |
9 |
Correct |
340 ms |
844 KB |
Output is correct |
10 |
Correct |
349 ms |
836 KB |
Output is correct |
11 |
Correct |
336 ms |
884 KB |
Output is correct |
12 |
Correct |
336 ms |
892 KB |
Output is correct |
13 |
Correct |
333 ms |
896 KB |
Output is correct |
14 |
Correct |
336 ms |
908 KB |
Output is correct |
15 |
Correct |
351 ms |
1016 KB |
Output is correct |
16 |
Correct |
366 ms |
904 KB |
Output is correct |
17 |
Correct |
340 ms |
860 KB |
Output is correct |
18 |
Correct |
397 ms |
848 KB |
Output is correct |
19 |
Correct |
848 ms |
8104 KB |
Output is correct |
20 |
Correct |
1064 ms |
8312 KB |
Output is correct |
21 |
Correct |
673 ms |
7352 KB |
Output is correct |
22 |
Correct |
516 ms |
6780 KB |
Output is correct |
23 |
Correct |
430 ms |
1308 KB |
Output is correct |
24 |
Correct |
400 ms |
1452 KB |
Output is correct |
25 |
Correct |
601 ms |
8120 KB |
Output is correct |
26 |
Correct |
603 ms |
8148 KB |
Output is correct |
27 |
Correct |
888 ms |
8296 KB |
Output is correct |
28 |
Correct |
764 ms |
8340 KB |
Output is correct |
29 |
Correct |
859 ms |
7428 KB |
Output is correct |
30 |
Correct |
460 ms |
1204 KB |
Output is correct |
31 |
Correct |
829 ms |
8180 KB |
Output is correct |
32 |
Correct |
650 ms |
7152 KB |
Output is correct |
33 |
Correct |
439 ms |
1216 KB |
Output is correct |
34 |
Correct |
725 ms |
8224 KB |
Output is correct |
35 |
Correct |
498 ms |
6244 KB |
Output is correct |
36 |
Correct |
397 ms |
1208 KB |
Output is correct |
37 |
Correct |
398 ms |
1184 KB |
Output is correct |
38 |
Correct |
1177 ms |
8200 KB |
Output is correct |
39 |
Correct |
753 ms |
8284 KB |
Output is correct |
40 |
Correct |
521 ms |
5076 KB |
Output is correct |
41 |
Correct |
1236 ms |
8420 KB |
Output is correct |
42 |
Correct |
1167 ms |
8644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
852 KB |
Output is correct |
2 |
Correct |
381 ms |
908 KB |
Output is correct |
3 |
Correct |
412 ms |
880 KB |
Output is correct |
4 |
Correct |
352 ms |
944 KB |
Output is correct |
5 |
Correct |
352 ms |
912 KB |
Output is correct |
6 |
Correct |
354 ms |
824 KB |
Output is correct |
7 |
Correct |
348 ms |
920 KB |
Output is correct |
8 |
Correct |
364 ms |
900 KB |
Output is correct |
9 |
Correct |
340 ms |
844 KB |
Output is correct |
10 |
Correct |
349 ms |
836 KB |
Output is correct |
11 |
Correct |
336 ms |
884 KB |
Output is correct |
12 |
Correct |
336 ms |
892 KB |
Output is correct |
13 |
Correct |
333 ms |
896 KB |
Output is correct |
14 |
Correct |
336 ms |
908 KB |
Output is correct |
15 |
Correct |
351 ms |
1016 KB |
Output is correct |
16 |
Correct |
366 ms |
904 KB |
Output is correct |
17 |
Correct |
340 ms |
860 KB |
Output is correct |
18 |
Correct |
397 ms |
848 KB |
Output is correct |
19 |
Correct |
374 ms |
884 KB |
Output is correct |
20 |
Correct |
507 ms |
928 KB |
Output is correct |
21 |
Correct |
363 ms |
968 KB |
Output is correct |
22 |
Correct |
306 ms |
880 KB |
Output is correct |
23 |
Correct |
376 ms |
848 KB |
Output is correct |
24 |
Correct |
337 ms |
800 KB |
Output is correct |
25 |
Correct |
361 ms |
816 KB |
Output is correct |
26 |
Correct |
385 ms |
812 KB |
Output is correct |
27 |
Correct |
351 ms |
808 KB |
Output is correct |
28 |
Correct |
366 ms |
760 KB |
Output is correct |
29 |
Correct |
356 ms |
956 KB |
Output is correct |
30 |
Correct |
326 ms |
820 KB |
Output is correct |
31 |
Correct |
369 ms |
972 KB |
Output is correct |
32 |
Correct |
390 ms |
844 KB |
Output is correct |
33 |
Correct |
385 ms |
1016 KB |
Output is correct |
34 |
Correct |
375 ms |
844 KB |
Output is correct |
35 |
Correct |
405 ms |
908 KB |
Output is correct |
36 |
Correct |
373 ms |
828 KB |
Output is correct |
37 |
Correct |
383 ms |
916 KB |
Output is correct |
38 |
Correct |
373 ms |
972 KB |
Output is correct |
39 |
Correct |
414 ms |
1128 KB |
Output is correct |
40 |
Correct |
382 ms |
888 KB |
Output is correct |
41 |
Correct |
417 ms |
864 KB |
Output is correct |
42 |
Correct |
375 ms |
840 KB |
Output is correct |
43 |
Correct |
354 ms |
888 KB |
Output is correct |
44 |
Correct |
387 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
852 KB |
Output is correct |
2 |
Correct |
381 ms |
908 KB |
Output is correct |
3 |
Correct |
412 ms |
880 KB |
Output is correct |
4 |
Correct |
352 ms |
944 KB |
Output is correct |
5 |
Correct |
352 ms |
912 KB |
Output is correct |
6 |
Correct |
354 ms |
824 KB |
Output is correct |
7 |
Correct |
348 ms |
920 KB |
Output is correct |
8 |
Correct |
364 ms |
900 KB |
Output is correct |
9 |
Correct |
340 ms |
844 KB |
Output is correct |
10 |
Correct |
349 ms |
836 KB |
Output is correct |
11 |
Correct |
336 ms |
884 KB |
Output is correct |
12 |
Correct |
336 ms |
892 KB |
Output is correct |
13 |
Correct |
333 ms |
896 KB |
Output is correct |
14 |
Correct |
336 ms |
908 KB |
Output is correct |
15 |
Correct |
351 ms |
1016 KB |
Output is correct |
16 |
Correct |
366 ms |
904 KB |
Output is correct |
17 |
Correct |
340 ms |
860 KB |
Output is correct |
18 |
Correct |
397 ms |
848 KB |
Output is correct |
19 |
Correct |
848 ms |
8104 KB |
Output is correct |
20 |
Correct |
1064 ms |
8312 KB |
Output is correct |
21 |
Correct |
673 ms |
7352 KB |
Output is correct |
22 |
Correct |
516 ms |
6780 KB |
Output is correct |
23 |
Correct |
430 ms |
1308 KB |
Output is correct |
24 |
Correct |
400 ms |
1452 KB |
Output is correct |
25 |
Correct |
601 ms |
8120 KB |
Output is correct |
26 |
Correct |
603 ms |
8148 KB |
Output is correct |
27 |
Correct |
888 ms |
8296 KB |
Output is correct |
28 |
Correct |
764 ms |
8340 KB |
Output is correct |
29 |
Correct |
859 ms |
7428 KB |
Output is correct |
30 |
Correct |
460 ms |
1204 KB |
Output is correct |
31 |
Correct |
829 ms |
8180 KB |
Output is correct |
32 |
Correct |
650 ms |
7152 KB |
Output is correct |
33 |
Correct |
439 ms |
1216 KB |
Output is correct |
34 |
Correct |
725 ms |
8224 KB |
Output is correct |
35 |
Correct |
498 ms |
6244 KB |
Output is correct |
36 |
Correct |
397 ms |
1208 KB |
Output is correct |
37 |
Correct |
398 ms |
1184 KB |
Output is correct |
38 |
Correct |
1177 ms |
8200 KB |
Output is correct |
39 |
Correct |
753 ms |
8284 KB |
Output is correct |
40 |
Correct |
521 ms |
5076 KB |
Output is correct |
41 |
Correct |
1236 ms |
8420 KB |
Output is correct |
42 |
Correct |
1167 ms |
8644 KB |
Output is correct |
43 |
Correct |
374 ms |
884 KB |
Output is correct |
44 |
Correct |
507 ms |
928 KB |
Output is correct |
45 |
Correct |
363 ms |
968 KB |
Output is correct |
46 |
Correct |
306 ms |
880 KB |
Output is correct |
47 |
Correct |
376 ms |
848 KB |
Output is correct |
48 |
Correct |
337 ms |
800 KB |
Output is correct |
49 |
Correct |
361 ms |
816 KB |
Output is correct |
50 |
Correct |
385 ms |
812 KB |
Output is correct |
51 |
Correct |
351 ms |
808 KB |
Output is correct |
52 |
Correct |
366 ms |
760 KB |
Output is correct |
53 |
Correct |
356 ms |
956 KB |
Output is correct |
54 |
Correct |
326 ms |
820 KB |
Output is correct |
55 |
Correct |
369 ms |
972 KB |
Output is correct |
56 |
Correct |
390 ms |
844 KB |
Output is correct |
57 |
Correct |
385 ms |
1016 KB |
Output is correct |
58 |
Correct |
375 ms |
844 KB |
Output is correct |
59 |
Correct |
405 ms |
908 KB |
Output is correct |
60 |
Correct |
373 ms |
828 KB |
Output is correct |
61 |
Correct |
383 ms |
916 KB |
Output is correct |
62 |
Correct |
373 ms |
972 KB |
Output is correct |
63 |
Correct |
414 ms |
1128 KB |
Output is correct |
64 |
Correct |
382 ms |
888 KB |
Output is correct |
65 |
Correct |
417 ms |
864 KB |
Output is correct |
66 |
Correct |
375 ms |
840 KB |
Output is correct |
67 |
Correct |
354 ms |
888 KB |
Output is correct |
68 |
Correct |
387 ms |
904 KB |
Output is correct |
69 |
Correct |
1459 ms |
20184 KB |
Output is correct |
70 |
Correct |
2185 ms |
23828 KB |
Output is correct |
71 |
Correct |
406 ms |
1488 KB |
Output is correct |
72 |
Correct |
443 ms |
1376 KB |
Output is correct |
73 |
Correct |
428 ms |
1372 KB |
Output is correct |
74 |
Correct |
597 ms |
9112 KB |
Output is correct |
75 |
Correct |
427 ms |
1412 KB |
Output is correct |
76 |
Correct |
646 ms |
10664 KB |
Output is correct |
77 |
Correct |
612 ms |
9100 KB |
Output is correct |
78 |
Correct |
450 ms |
1532 KB |
Output is correct |
79 |
Correct |
422 ms |
1420 KB |
Output is correct |
80 |
Correct |
810 ms |
17220 KB |
Output is correct |
81 |
Correct |
508 ms |
2180 KB |
Output is correct |
82 |
Correct |
1024 ms |
23664 KB |
Output is correct |
83 |
Correct |
1018 ms |
22112 KB |
Output is correct |
84 |
Correct |
485 ms |
2020 KB |
Output is correct |
85 |
Correct |
496 ms |
1996 KB |
Output is correct |
86 |
Correct |
1289 ms |
18112 KB |
Output is correct |
87 |
Correct |
1354 ms |
23704 KB |
Output is correct |
88 |
Correct |
583 ms |
2204 KB |
Output is correct |
89 |
Correct |
1183 ms |
21484 KB |
Output is correct |
90 |
Correct |
1316 ms |
23804 KB |
Output is correct |
91 |
Correct |
590 ms |
2304 KB |
Output is correct |
92 |
Correct |
851 ms |
17724 KB |
Output is correct |
93 |
Correct |
480 ms |
2096 KB |
Output is correct |
94 |
Correct |
489 ms |
2092 KB |
Output is correct |
95 |
Correct |
488 ms |
2100 KB |
Output is correct |
96 |
Correct |
1228 ms |
8280 KB |
Output is correct |
97 |
Correct |
1513 ms |
23848 KB |
Output is correct |
98 |
Correct |
850 ms |
15080 KB |
Output is correct |
99 |
Correct |
2111 ms |
24008 KB |
Output is correct |
100 |
Correct |
2182 ms |
23760 KB |
Output is correct |