#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 = 0;
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;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
876 KB |
Output is correct |
2 |
Correct |
337 ms |
888 KB |
Output is correct |
3 |
Correct |
381 ms |
844 KB |
Output is correct |
4 |
Correct |
339 ms |
980 KB |
Output is correct |
5 |
Correct |
343 ms |
940 KB |
Output is correct |
6 |
Correct |
367 ms |
876 KB |
Output is correct |
7 |
Correct |
347 ms |
896 KB |
Output is correct |
8 |
Correct |
342 ms |
860 KB |
Output is correct |
9 |
Correct |
338 ms |
808 KB |
Output is correct |
10 |
Correct |
369 ms |
924 KB |
Output is correct |
11 |
Correct |
325 ms |
1024 KB |
Output is correct |
12 |
Correct |
331 ms |
812 KB |
Output is correct |
13 |
Correct |
352 ms |
824 KB |
Output is correct |
14 |
Correct |
350 ms |
988 KB |
Output is correct |
15 |
Correct |
336 ms |
804 KB |
Output is correct |
16 |
Correct |
373 ms |
928 KB |
Output is correct |
17 |
Correct |
340 ms |
844 KB |
Output is correct |
18 |
Correct |
387 ms |
908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
876 KB |
Output is correct |
2 |
Correct |
337 ms |
888 KB |
Output is correct |
3 |
Correct |
381 ms |
844 KB |
Output is correct |
4 |
Correct |
339 ms |
980 KB |
Output is correct |
5 |
Correct |
343 ms |
940 KB |
Output is correct |
6 |
Correct |
367 ms |
876 KB |
Output is correct |
7 |
Correct |
347 ms |
896 KB |
Output is correct |
8 |
Correct |
342 ms |
860 KB |
Output is correct |
9 |
Correct |
338 ms |
808 KB |
Output is correct |
10 |
Correct |
369 ms |
924 KB |
Output is correct |
11 |
Correct |
325 ms |
1024 KB |
Output is correct |
12 |
Correct |
331 ms |
812 KB |
Output is correct |
13 |
Correct |
352 ms |
824 KB |
Output is correct |
14 |
Correct |
350 ms |
988 KB |
Output is correct |
15 |
Correct |
336 ms |
804 KB |
Output is correct |
16 |
Correct |
373 ms |
928 KB |
Output is correct |
17 |
Correct |
340 ms |
844 KB |
Output is correct |
18 |
Correct |
387 ms |
908 KB |
Output is correct |
19 |
Correct |
872 ms |
8160 KB |
Output is correct |
20 |
Correct |
1059 ms |
8160 KB |
Output is correct |
21 |
Correct |
676 ms |
7288 KB |
Output is correct |
22 |
Correct |
550 ms |
6728 KB |
Output is correct |
23 |
Correct |
415 ms |
1224 KB |
Output is correct |
24 |
Correct |
415 ms |
1260 KB |
Output is correct |
25 |
Incorrect |
659 ms |
8096 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
876 KB |
Output is correct |
2 |
Correct |
337 ms |
888 KB |
Output is correct |
3 |
Correct |
381 ms |
844 KB |
Output is correct |
4 |
Correct |
339 ms |
980 KB |
Output is correct |
5 |
Correct |
343 ms |
940 KB |
Output is correct |
6 |
Correct |
367 ms |
876 KB |
Output is correct |
7 |
Correct |
347 ms |
896 KB |
Output is correct |
8 |
Correct |
342 ms |
860 KB |
Output is correct |
9 |
Correct |
338 ms |
808 KB |
Output is correct |
10 |
Correct |
369 ms |
924 KB |
Output is correct |
11 |
Correct |
325 ms |
1024 KB |
Output is correct |
12 |
Correct |
331 ms |
812 KB |
Output is correct |
13 |
Correct |
352 ms |
824 KB |
Output is correct |
14 |
Correct |
350 ms |
988 KB |
Output is correct |
15 |
Correct |
336 ms |
804 KB |
Output is correct |
16 |
Correct |
373 ms |
928 KB |
Output is correct |
17 |
Correct |
340 ms |
844 KB |
Output is correct |
18 |
Correct |
387 ms |
908 KB |
Output is correct |
19 |
Correct |
370 ms |
840 KB |
Output is correct |
20 |
Correct |
504 ms |
844 KB |
Output is correct |
21 |
Correct |
374 ms |
880 KB |
Output is correct |
22 |
Correct |
308 ms |
900 KB |
Output is correct |
23 |
Correct |
340 ms |
948 KB |
Output is correct |
24 |
Correct |
328 ms |
904 KB |
Output is correct |
25 |
Correct |
378 ms |
844 KB |
Output is correct |
26 |
Correct |
357 ms |
808 KB |
Output is correct |
27 |
Correct |
349 ms |
856 KB |
Output is correct |
28 |
Correct |
334 ms |
896 KB |
Output is correct |
29 |
Correct |
342 ms |
876 KB |
Output is correct |
30 |
Correct |
321 ms |
828 KB |
Output is correct |
31 |
Correct |
403 ms |
868 KB |
Output is correct |
32 |
Correct |
396 ms |
932 KB |
Output is correct |
33 |
Correct |
379 ms |
1024 KB |
Output is correct |
34 |
Correct |
364 ms |
900 KB |
Output is correct |
35 |
Correct |
390 ms |
1028 KB |
Output is correct |
36 |
Correct |
381 ms |
1024 KB |
Output is correct |
37 |
Correct |
402 ms |
892 KB |
Output is correct |
38 |
Correct |
364 ms |
920 KB |
Output is correct |
39 |
Correct |
366 ms |
812 KB |
Output is correct |
40 |
Correct |
368 ms |
904 KB |
Output is correct |
41 |
Correct |
401 ms |
912 KB |
Output is correct |
42 |
Correct |
381 ms |
812 KB |
Output is correct |
43 |
Correct |
378 ms |
924 KB |
Output is correct |
44 |
Correct |
379 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
876 KB |
Output is correct |
2 |
Correct |
337 ms |
888 KB |
Output is correct |
3 |
Correct |
381 ms |
844 KB |
Output is correct |
4 |
Correct |
339 ms |
980 KB |
Output is correct |
5 |
Correct |
343 ms |
940 KB |
Output is correct |
6 |
Correct |
367 ms |
876 KB |
Output is correct |
7 |
Correct |
347 ms |
896 KB |
Output is correct |
8 |
Correct |
342 ms |
860 KB |
Output is correct |
9 |
Correct |
338 ms |
808 KB |
Output is correct |
10 |
Correct |
369 ms |
924 KB |
Output is correct |
11 |
Correct |
325 ms |
1024 KB |
Output is correct |
12 |
Correct |
331 ms |
812 KB |
Output is correct |
13 |
Correct |
352 ms |
824 KB |
Output is correct |
14 |
Correct |
350 ms |
988 KB |
Output is correct |
15 |
Correct |
336 ms |
804 KB |
Output is correct |
16 |
Correct |
373 ms |
928 KB |
Output is correct |
17 |
Correct |
340 ms |
844 KB |
Output is correct |
18 |
Correct |
387 ms |
908 KB |
Output is correct |
19 |
Correct |
872 ms |
8160 KB |
Output is correct |
20 |
Correct |
1059 ms |
8160 KB |
Output is correct |
21 |
Correct |
676 ms |
7288 KB |
Output is correct |
22 |
Correct |
550 ms |
6728 KB |
Output is correct |
23 |
Correct |
415 ms |
1224 KB |
Output is correct |
24 |
Correct |
415 ms |
1260 KB |
Output is correct |
25 |
Incorrect |
659 ms |
8096 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |