#include<bits/stdc++.h>
#define ll long long
const int nmax = 2e5 + 5, N = 1e6;
const ll oo = 1e9 + 5, base = 311;
const int lg = 62, tx = 26;
const ll mod = 1e9 + 7, mod2 = 1e9+3;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;
int n;
int a[5][nmax];
pii get(vector<int> &tmp){
pii tx = {0, 0};
for(auto p : tmp){
tx.fi = (tx.fi * base + p) % mod;
tx.se = (tx.se * base + p) % mod2;
}
return tx;
}
map<pii, int> vis;
vector<pii>lol;
void dfs(vector<int> tmp){
vis[get(tmp)] = 1;
vector<int> one;
if(tmp.size()) lol.push_back(get(tmp));
for(int i = 1; i <= 3; ++i){
one.clear();
if(tmp.empty()){
for(int j = 1;j <= n; ++j) one.push_back(a[i][j]);
}
else{
for(int j = 1; j <= n; ++j){
if(tmp[j - 1] == a[i][j]) one.push_back(tmp[j - 1]);
else one.push_back(tmp[j - 1] ^ a[i][j]);
}
}
if(vis[get(one)]) continue;
dfs(one);
}
}
int s[nmax];
pii tree[nmax << 2];
pii h[5][nmax];
ll pw[5][nmax];
int G[nmax << 2], lz[nmax << 2];
void build(int id, int l, int r){
G[id] = r - l + 1;
if(l == r){
tree[id] = {s[l], s[l]};
return;
}
int mid =r + l >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
tree[id].fi = (tree[id << 1].fi * pw[0][r - mid] + tree[id << 1 | 1].fi) % mod;
tree[id].se = (tree[id << 1].se * pw[1][r - mid] + tree[id << 1 | 1].se) % mod2;
}
void fix(int id, int val){
if(val == 0) return;
int x = G[id];
tree[id] = h[val][x];
lz[id] = val;
}
void down(int id){
fix(id << 1, lz[id]);
fix(id << 1 | 1, lz[id]);
lz[id] = 0;
}
void update(int id, int l, int r, int u, int v, int k){
if(l > v || r < u) return;
if(l >= u && r <= v){
// cout << k << ' ';
return fix(id, k);
}
down(id);
int mid = r + l >> 1;
update(id << 1, l, mid, u, v, k);
update(id << 1 | 1, mid + 1, r, u, v, k);
tree[id].fi = (tree[id << 1].fi * pw[0][r - mid] + tree[id << 1 | 1].fi) % mod;
tree[id].se = (tree[id << 1].se * pw[1][r - mid] + tree[id << 1 | 1].se) % mod2;
}
bool check(){
for(auto p : lol) if(tree[1] == p) return 1;
return 0;
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> n;
for(int i = 1; i <= 3; ++i){
for(int j = 1; j <= n; ++j){
char x;
cin >> x;
if(x == 'J') a[i][j] = 1;
else if(x == 'O') a[i][j] = 2;
else a[i][j] = 3;
}
}
vector<int> tmp;
dfs(tmp);
int q;cin >> q;
int cur = 0;
for(int i = 1; i <= n; ++i){
char x;
cin >> x;
if(x == 'J')s[i] = 1;
else if(x == 'O')s[i] = 2;
else s[i] = 3;
}
pw[0][0] = pw[1][0] = 1;
for(int i = 1; i <= n; ++i){
pw[0][i] = pw[0][i - 1] * base % mod;
pw[1][i] = pw[1][i - 1] * base % mod2;
}
for(int e = 1; e <= 3; ++e){
pii tx = {0, 0};
for(int i = 1; i <= n; ++i){
tx.fi = (tx.fi * base + e) % mod;
tx.se = (tx.se * base + e) % mod2;
h[e][i] = tx;
}
}
build(1, 1, n);
if(check()) cout << "Yes";
else cout << "No";
cout << endl;
while(q--){
int l, r, k;
char x;
cin >> l >> r >> x;
if(x == 'J')k = 1;
else if(x == 'O')k= 2;
else k= 3;
update(1, 1, n, l, r, k);
if(check()) cout << "Yes";
else cout << "No";
cout << endl;
}
}
/*
4
JOJO
JJOI
OJOO
1
OOOO
1 4 O
2 2 J
2 4 I
*/
Compilation message
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:59:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
59 | int mid =r + l >> 1;
| ~~^~~
Main.cpp: In function 'void update(int, int, int, int, int, int)':
Main.cpp:83:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
83 | int mid = r + l >> 1;
| ~~^~~
Main.cpp: At global scope:
Main.cpp:94:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
94 | main(){
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:112:9: warning: unused variable 'cur' [-Wunused-variable]
112 | int cur = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
2508 KB |
Output is correct |
2 |
Correct |
52 ms |
2644 KB |
Output is correct |
3 |
Correct |
52 ms |
2336 KB |
Output is correct |
4 |
Correct |
45 ms |
2388 KB |
Output is correct |
5 |
Correct |
44 ms |
2384 KB |
Output is correct |
6 |
Correct |
44 ms |
2388 KB |
Output is correct |
7 |
Correct |
45 ms |
2388 KB |
Output is correct |
8 |
Correct |
48 ms |
2532 KB |
Output is correct |
9 |
Correct |
53 ms |
2648 KB |
Output is correct |
10 |
Correct |
48 ms |
2640 KB |
Output is correct |
11 |
Correct |
52 ms |
2644 KB |
Output is correct |
12 |
Correct |
62 ms |
2648 KB |
Output is correct |
13 |
Correct |
47 ms |
2640 KB |
Output is correct |
14 |
Correct |
47 ms |
2640 KB |
Output is correct |
15 |
Correct |
47 ms |
2648 KB |
Output is correct |
16 |
Correct |
46 ms |
2644 KB |
Output is correct |
17 |
Correct |
52 ms |
2640 KB |
Output is correct |
18 |
Correct |
47 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
2508 KB |
Output is correct |
2 |
Correct |
52 ms |
2644 KB |
Output is correct |
3 |
Correct |
52 ms |
2336 KB |
Output is correct |
4 |
Correct |
45 ms |
2388 KB |
Output is correct |
5 |
Correct |
44 ms |
2384 KB |
Output is correct |
6 |
Correct |
44 ms |
2388 KB |
Output is correct |
7 |
Correct |
45 ms |
2388 KB |
Output is correct |
8 |
Correct |
48 ms |
2532 KB |
Output is correct |
9 |
Correct |
53 ms |
2648 KB |
Output is correct |
10 |
Correct |
48 ms |
2640 KB |
Output is correct |
11 |
Correct |
52 ms |
2644 KB |
Output is correct |
12 |
Correct |
62 ms |
2648 KB |
Output is correct |
13 |
Correct |
47 ms |
2640 KB |
Output is correct |
14 |
Correct |
47 ms |
2640 KB |
Output is correct |
15 |
Correct |
47 ms |
2648 KB |
Output is correct |
16 |
Correct |
46 ms |
2644 KB |
Output is correct |
17 |
Correct |
52 ms |
2640 KB |
Output is correct |
18 |
Correct |
47 ms |
2360 KB |
Output is correct |
19 |
Correct |
187 ms |
32740 KB |
Output is correct |
20 |
Correct |
182 ms |
31032 KB |
Output is correct |
21 |
Correct |
140 ms |
31736 KB |
Output is correct |
22 |
Correct |
132 ms |
29828 KB |
Output is correct |
23 |
Correct |
83 ms |
5152 KB |
Output is correct |
24 |
Correct |
79 ms |
5152 KB |
Output is correct |
25 |
Correct |
141 ms |
32784 KB |
Output is correct |
26 |
Correct |
146 ms |
32780 KB |
Output is correct |
27 |
Correct |
174 ms |
32816 KB |
Output is correct |
28 |
Correct |
155 ms |
32784 KB |
Output is correct |
29 |
Correct |
145 ms |
32336 KB |
Output is correct |
30 |
Correct |
86 ms |
5152 KB |
Output is correct |
31 |
Correct |
150 ms |
32788 KB |
Output is correct |
32 |
Correct |
144 ms |
31116 KB |
Output is correct |
33 |
Correct |
78 ms |
5144 KB |
Output is correct |
34 |
Correct |
165 ms |
32784 KB |
Output is correct |
35 |
Correct |
123 ms |
28264 KB |
Output is correct |
36 |
Correct |
78 ms |
5148 KB |
Output is correct |
37 |
Correct |
92 ms |
5040 KB |
Output is correct |
38 |
Correct |
159 ms |
30988 KB |
Output is correct |
39 |
Correct |
123 ms |
30740 KB |
Output is correct |
40 |
Correct |
114 ms |
20796 KB |
Output is correct |
41 |
Correct |
186 ms |
33036 KB |
Output is correct |
42 |
Correct |
62 ms |
30072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
2508 KB |
Output is correct |
2 |
Correct |
52 ms |
2644 KB |
Output is correct |
3 |
Correct |
52 ms |
2336 KB |
Output is correct |
4 |
Correct |
45 ms |
2388 KB |
Output is correct |
5 |
Correct |
44 ms |
2384 KB |
Output is correct |
6 |
Correct |
44 ms |
2388 KB |
Output is correct |
7 |
Correct |
45 ms |
2388 KB |
Output is correct |
8 |
Correct |
48 ms |
2532 KB |
Output is correct |
9 |
Correct |
53 ms |
2648 KB |
Output is correct |
10 |
Correct |
48 ms |
2640 KB |
Output is correct |
11 |
Correct |
52 ms |
2644 KB |
Output is correct |
12 |
Correct |
62 ms |
2648 KB |
Output is correct |
13 |
Correct |
47 ms |
2640 KB |
Output is correct |
14 |
Correct |
47 ms |
2640 KB |
Output is correct |
15 |
Correct |
47 ms |
2648 KB |
Output is correct |
16 |
Correct |
46 ms |
2644 KB |
Output is correct |
17 |
Correct |
52 ms |
2640 KB |
Output is correct |
18 |
Correct |
47 ms |
2360 KB |
Output is correct |
19 |
Correct |
50 ms |
2480 KB |
Output is correct |
20 |
Correct |
53 ms |
2348 KB |
Output is correct |
21 |
Correct |
53 ms |
2640 KB |
Output is correct |
22 |
Correct |
41 ms |
2316 KB |
Output is correct |
23 |
Correct |
47 ms |
2644 KB |
Output is correct |
24 |
Correct |
45 ms |
2384 KB |
Output is correct |
25 |
Correct |
48 ms |
2684 KB |
Output is correct |
26 |
Correct |
47 ms |
2656 KB |
Output is correct |
27 |
Correct |
46 ms |
2644 KB |
Output is correct |
28 |
Correct |
48 ms |
2312 KB |
Output is correct |
29 |
Correct |
48 ms |
2680 KB |
Output is correct |
30 |
Correct |
41 ms |
2388 KB |
Output is correct |
31 |
Correct |
48 ms |
2688 KB |
Output is correct |
32 |
Correct |
47 ms |
2640 KB |
Output is correct |
33 |
Correct |
48 ms |
2564 KB |
Output is correct |
34 |
Correct |
45 ms |
2388 KB |
Output is correct |
35 |
Correct |
48 ms |
2640 KB |
Output is correct |
36 |
Correct |
48 ms |
2640 KB |
Output is correct |
37 |
Correct |
48 ms |
2520 KB |
Output is correct |
38 |
Correct |
48 ms |
2592 KB |
Output is correct |
39 |
Correct |
48 ms |
2640 KB |
Output is correct |
40 |
Correct |
48 ms |
2644 KB |
Output is correct |
41 |
Correct |
48 ms |
2640 KB |
Output is correct |
42 |
Correct |
54 ms |
2624 KB |
Output is correct |
43 |
Correct |
45 ms |
2640 KB |
Output is correct |
44 |
Correct |
49 ms |
2472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
2508 KB |
Output is correct |
2 |
Correct |
52 ms |
2644 KB |
Output is correct |
3 |
Correct |
52 ms |
2336 KB |
Output is correct |
4 |
Correct |
45 ms |
2388 KB |
Output is correct |
5 |
Correct |
44 ms |
2384 KB |
Output is correct |
6 |
Correct |
44 ms |
2388 KB |
Output is correct |
7 |
Correct |
45 ms |
2388 KB |
Output is correct |
8 |
Correct |
48 ms |
2532 KB |
Output is correct |
9 |
Correct |
53 ms |
2648 KB |
Output is correct |
10 |
Correct |
48 ms |
2640 KB |
Output is correct |
11 |
Correct |
52 ms |
2644 KB |
Output is correct |
12 |
Correct |
62 ms |
2648 KB |
Output is correct |
13 |
Correct |
47 ms |
2640 KB |
Output is correct |
14 |
Correct |
47 ms |
2640 KB |
Output is correct |
15 |
Correct |
47 ms |
2648 KB |
Output is correct |
16 |
Correct |
46 ms |
2644 KB |
Output is correct |
17 |
Correct |
52 ms |
2640 KB |
Output is correct |
18 |
Correct |
47 ms |
2360 KB |
Output is correct |
19 |
Correct |
187 ms |
32740 KB |
Output is correct |
20 |
Correct |
182 ms |
31032 KB |
Output is correct |
21 |
Correct |
140 ms |
31736 KB |
Output is correct |
22 |
Correct |
132 ms |
29828 KB |
Output is correct |
23 |
Correct |
83 ms |
5152 KB |
Output is correct |
24 |
Correct |
79 ms |
5152 KB |
Output is correct |
25 |
Correct |
141 ms |
32784 KB |
Output is correct |
26 |
Correct |
146 ms |
32780 KB |
Output is correct |
27 |
Correct |
174 ms |
32816 KB |
Output is correct |
28 |
Correct |
155 ms |
32784 KB |
Output is correct |
29 |
Correct |
145 ms |
32336 KB |
Output is correct |
30 |
Correct |
86 ms |
5152 KB |
Output is correct |
31 |
Correct |
150 ms |
32788 KB |
Output is correct |
32 |
Correct |
144 ms |
31116 KB |
Output is correct |
33 |
Correct |
78 ms |
5144 KB |
Output is correct |
34 |
Correct |
165 ms |
32784 KB |
Output is correct |
35 |
Correct |
123 ms |
28264 KB |
Output is correct |
36 |
Correct |
78 ms |
5148 KB |
Output is correct |
37 |
Correct |
92 ms |
5040 KB |
Output is correct |
38 |
Correct |
159 ms |
30988 KB |
Output is correct |
39 |
Correct |
123 ms |
30740 KB |
Output is correct |
40 |
Correct |
114 ms |
20796 KB |
Output is correct |
41 |
Correct |
186 ms |
33036 KB |
Output is correct |
42 |
Correct |
62 ms |
30072 KB |
Output is correct |
43 |
Correct |
50 ms |
2480 KB |
Output is correct |
44 |
Correct |
53 ms |
2348 KB |
Output is correct |
45 |
Correct |
53 ms |
2640 KB |
Output is correct |
46 |
Correct |
41 ms |
2316 KB |
Output is correct |
47 |
Correct |
47 ms |
2644 KB |
Output is correct |
48 |
Correct |
45 ms |
2384 KB |
Output is correct |
49 |
Correct |
48 ms |
2684 KB |
Output is correct |
50 |
Correct |
47 ms |
2656 KB |
Output is correct |
51 |
Correct |
46 ms |
2644 KB |
Output is correct |
52 |
Correct |
48 ms |
2312 KB |
Output is correct |
53 |
Correct |
48 ms |
2680 KB |
Output is correct |
54 |
Correct |
41 ms |
2388 KB |
Output is correct |
55 |
Correct |
48 ms |
2688 KB |
Output is correct |
56 |
Correct |
47 ms |
2640 KB |
Output is correct |
57 |
Correct |
48 ms |
2564 KB |
Output is correct |
58 |
Correct |
45 ms |
2388 KB |
Output is correct |
59 |
Correct |
48 ms |
2640 KB |
Output is correct |
60 |
Correct |
48 ms |
2640 KB |
Output is correct |
61 |
Correct |
48 ms |
2520 KB |
Output is correct |
62 |
Correct |
48 ms |
2592 KB |
Output is correct |
63 |
Correct |
48 ms |
2640 KB |
Output is correct |
64 |
Correct |
48 ms |
2644 KB |
Output is correct |
65 |
Correct |
48 ms |
2640 KB |
Output is correct |
66 |
Correct |
54 ms |
2624 KB |
Output is correct |
67 |
Correct |
45 ms |
2640 KB |
Output is correct |
68 |
Correct |
49 ms |
2472 KB |
Output is correct |
69 |
Correct |
215 ms |
29844 KB |
Output is correct |
70 |
Correct |
247 ms |
31172 KB |
Output is correct |
71 |
Correct |
79 ms |
5088 KB |
Output is correct |
72 |
Correct |
79 ms |
5072 KB |
Output is correct |
73 |
Correct |
80 ms |
5328 KB |
Output is correct |
74 |
Correct |
141 ms |
29792 KB |
Output is correct |
75 |
Correct |
81 ms |
5092 KB |
Output is correct |
76 |
Correct |
164 ms |
32852 KB |
Output is correct |
77 |
Correct |
147 ms |
29768 KB |
Output is correct |
78 |
Correct |
79 ms |
5272 KB |
Output is correct |
79 |
Correct |
86 ms |
5072 KB |
Output is correct |
80 |
Correct |
174 ms |
27656 KB |
Output is correct |
81 |
Correct |
82 ms |
5108 KB |
Output is correct |
82 |
Correct |
211 ms |
32760 KB |
Output is correct |
83 |
Correct |
227 ms |
31672 KB |
Output is correct |
84 |
Correct |
86 ms |
5108 KB |
Output is correct |
85 |
Correct |
82 ms |
5112 KB |
Output is correct |
86 |
Correct |
181 ms |
28680 KB |
Output is correct |
87 |
Correct |
206 ms |
32784 KB |
Output is correct |
88 |
Correct |
87 ms |
5292 KB |
Output is correct |
89 |
Correct |
193 ms |
30828 KB |
Output is correct |
90 |
Correct |
206 ms |
32748 KB |
Output is correct |
91 |
Correct |
86 ms |
5096 KB |
Output is correct |
92 |
Correct |
195 ms |
28280 KB |
Output is correct |
93 |
Correct |
83 ms |
5256 KB |
Output is correct |
94 |
Correct |
82 ms |
5108 KB |
Output is correct |
95 |
Correct |
93 ms |
5100 KB |
Output is correct |
96 |
Correct |
161 ms |
31064 KB |
Output is correct |
97 |
Correct |
179 ms |
30724 KB |
Output is correct |
98 |
Correct |
172 ms |
20744 KB |
Output is correct |
99 |
Correct |
272 ms |
32992 KB |
Output is correct |
100 |
Correct |
130 ms |
30024 KB |
Output is correct |