#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const int MOD=1000000007;
const int P=177013;
ll powp[200005];
mt19937 rng(177013);
#define i3 tuple<int,int,int>
i3 conv(i3 i,i3 j){
int ia,ib,ic;
int ja,jb,jc;
tie(ia,ib,ic)=i;
tie(ja,jb,jc)=j;
return {
(6-ia-ja)%3,
(6-ib-jb)%3,
(6-ic-jc)%3
};
}
set<i3> s[10];
int n,q;
string st[3];
ll v[3][200005];
map<char,int> id;
ll hh[3];
set<int> good;
string qu;
struct node{
int s,e,m;
ll val=0,lazy=-1;
ll mul=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
rep(x,s,e+1) mul=(mul+powp[x])%MOD;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void propo(){
if (lazy!=-1){
val=hh[lazy]*mul%MOD;
if (s!=e){
l->lazy=lazy;
r->lazy=lazy;
}
lazy=-1;
}
}
void update(int i,int j,int k){
propo();
if (s==i && e==j) lazy=k;
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=(l->val+r->val)%MOD;
}
}
} *root;
int main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
powp[0]=1;
rep(x,1,200005) powp[x]=powp[x-1]*P%MOD;
id['J']=0;
id['O']=1;
id['I']=2;
rep(x,0,3) hh[x]=rng()%MOD;
//rep(x,0,3) hh[x]=x+1;
s[0].insert({1,0,0}),s[0].insert({0,1,0}),s[0].insert({0,0,1});
rep(x,0,9){
s[x+1]=s[x];
for (auto &it:s[x]) for (auto &it2:s[x]){
s[x+1].insert(conv(it,it2));
}
}
cin>>n;
rep(x,0,3) cin>>st[x];
rep(x,0,3) rep(y,0,n){
v[x][y]=id[st[x][y]];
}
for (auto &it:s[9]){
ll arr[3];
tie(arr[0],arr[1],arr[2])=it;
ll curr=0;
rep(x,0,n){
ll base=0;
rep(y,0,3) base=(base+v[y][x]*arr[y])%3;
curr=(curr+hh[base]*powp[x])%MOD;
//cout<<base<<" ";
}
//cout<<endl;
good.insert(curr);
//cout<<curr<<endl;
}
cin>>q;
cin>>qu;
root=new node(0,200005);
rep(x,0,n) root->update(x,x,id[qu[x]]);
//rep(x,0,n) cout<<id[qu[x]]<<" "; cout<<endl;
//cout<<root->val<<endl;
if (good.count(root->val)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
int a,b;
char c;
while (q--){
cin>>a>>b>>c;
root->update(a-1,b-1,id[c]);
if (good.count(root->val)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
Compilation message
Main.cpp: In constructor 'node::node(int, int)':
Main.cpp:62:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
27396 KB |
Output is correct |
2 |
Correct |
162 ms |
27480 KB |
Output is correct |
3 |
Correct |
158 ms |
27564 KB |
Output is correct |
4 |
Correct |
143 ms |
27488 KB |
Output is correct |
5 |
Correct |
147 ms |
27732 KB |
Output is correct |
6 |
Correct |
140 ms |
27488 KB |
Output is correct |
7 |
Correct |
147 ms |
27444 KB |
Output is correct |
8 |
Correct |
147 ms |
27532 KB |
Output is correct |
9 |
Correct |
155 ms |
27528 KB |
Output is correct |
10 |
Correct |
152 ms |
27636 KB |
Output is correct |
11 |
Correct |
148 ms |
27500 KB |
Output is correct |
12 |
Correct |
148 ms |
27480 KB |
Output is correct |
13 |
Correct |
154 ms |
27460 KB |
Output is correct |
14 |
Correct |
148 ms |
27432 KB |
Output is correct |
15 |
Correct |
155 ms |
27444 KB |
Output is correct |
16 |
Correct |
155 ms |
27536 KB |
Output is correct |
17 |
Correct |
152 ms |
27500 KB |
Output is correct |
18 |
Correct |
156 ms |
27524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
27396 KB |
Output is correct |
2 |
Correct |
162 ms |
27480 KB |
Output is correct |
3 |
Correct |
158 ms |
27564 KB |
Output is correct |
4 |
Correct |
143 ms |
27488 KB |
Output is correct |
5 |
Correct |
147 ms |
27732 KB |
Output is correct |
6 |
Correct |
140 ms |
27488 KB |
Output is correct |
7 |
Correct |
147 ms |
27444 KB |
Output is correct |
8 |
Correct |
147 ms |
27532 KB |
Output is correct |
9 |
Correct |
155 ms |
27528 KB |
Output is correct |
10 |
Correct |
152 ms |
27636 KB |
Output is correct |
11 |
Correct |
148 ms |
27500 KB |
Output is correct |
12 |
Correct |
148 ms |
27480 KB |
Output is correct |
13 |
Correct |
154 ms |
27460 KB |
Output is correct |
14 |
Correct |
148 ms |
27432 KB |
Output is correct |
15 |
Correct |
155 ms |
27444 KB |
Output is correct |
16 |
Correct |
155 ms |
27536 KB |
Output is correct |
17 |
Correct |
152 ms |
27500 KB |
Output is correct |
18 |
Correct |
156 ms |
27524 KB |
Output is correct |
19 |
Correct |
472 ms |
33052 KB |
Output is correct |
20 |
Correct |
404 ms |
33004 KB |
Output is correct |
21 |
Correct |
342 ms |
32576 KB |
Output is correct |
22 |
Correct |
318 ms |
32060 KB |
Output is correct |
23 |
Correct |
197 ms |
27840 KB |
Output is correct |
24 |
Correct |
186 ms |
27708 KB |
Output is correct |
25 |
Correct |
355 ms |
32956 KB |
Output is correct |
26 |
Correct |
359 ms |
32936 KB |
Output is correct |
27 |
Correct |
406 ms |
32992 KB |
Output is correct |
28 |
Correct |
430 ms |
33072 KB |
Output is correct |
29 |
Correct |
390 ms |
32748 KB |
Output is correct |
30 |
Correct |
202 ms |
27736 KB |
Output is correct |
31 |
Correct |
377 ms |
33056 KB |
Output is correct |
32 |
Correct |
399 ms |
32556 KB |
Output is correct |
33 |
Correct |
196 ms |
27740 KB |
Output is correct |
34 |
Correct |
395 ms |
33132 KB |
Output is correct |
35 |
Correct |
297 ms |
31536 KB |
Output is correct |
36 |
Correct |
189 ms |
27812 KB |
Output is correct |
37 |
Correct |
188 ms |
27712 KB |
Output is correct |
38 |
Correct |
380 ms |
32948 KB |
Output is correct |
39 |
Correct |
234 ms |
32936 KB |
Output is correct |
40 |
Correct |
299 ms |
31028 KB |
Output is correct |
41 |
Correct |
535 ms |
33364 KB |
Output is correct |
42 |
Correct |
220 ms |
33176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
27396 KB |
Output is correct |
2 |
Correct |
162 ms |
27480 KB |
Output is correct |
3 |
Correct |
158 ms |
27564 KB |
Output is correct |
4 |
Correct |
143 ms |
27488 KB |
Output is correct |
5 |
Correct |
147 ms |
27732 KB |
Output is correct |
6 |
Correct |
140 ms |
27488 KB |
Output is correct |
7 |
Correct |
147 ms |
27444 KB |
Output is correct |
8 |
Correct |
147 ms |
27532 KB |
Output is correct |
9 |
Correct |
155 ms |
27528 KB |
Output is correct |
10 |
Correct |
152 ms |
27636 KB |
Output is correct |
11 |
Correct |
148 ms |
27500 KB |
Output is correct |
12 |
Correct |
148 ms |
27480 KB |
Output is correct |
13 |
Correct |
154 ms |
27460 KB |
Output is correct |
14 |
Correct |
148 ms |
27432 KB |
Output is correct |
15 |
Correct |
155 ms |
27444 KB |
Output is correct |
16 |
Correct |
155 ms |
27536 KB |
Output is correct |
17 |
Correct |
152 ms |
27500 KB |
Output is correct |
18 |
Correct |
156 ms |
27524 KB |
Output is correct |
19 |
Correct |
153 ms |
27416 KB |
Output is correct |
20 |
Correct |
161 ms |
27432 KB |
Output is correct |
21 |
Correct |
151 ms |
27548 KB |
Output is correct |
22 |
Correct |
148 ms |
27436 KB |
Output is correct |
23 |
Correct |
150 ms |
27588 KB |
Output is correct |
24 |
Correct |
158 ms |
27500 KB |
Output is correct |
25 |
Correct |
148 ms |
27464 KB |
Output is correct |
26 |
Correct |
165 ms |
27480 KB |
Output is correct |
27 |
Correct |
148 ms |
27448 KB |
Output is correct |
28 |
Correct |
154 ms |
27380 KB |
Output is correct |
29 |
Correct |
150 ms |
27460 KB |
Output is correct |
30 |
Correct |
143 ms |
27460 KB |
Output is correct |
31 |
Correct |
150 ms |
27460 KB |
Output is correct |
32 |
Correct |
167 ms |
27464 KB |
Output is correct |
33 |
Correct |
165 ms |
27424 KB |
Output is correct |
34 |
Correct |
147 ms |
27472 KB |
Output is correct |
35 |
Correct |
156 ms |
27464 KB |
Output is correct |
36 |
Correct |
157 ms |
27532 KB |
Output is correct |
37 |
Correct |
157 ms |
27444 KB |
Output is correct |
38 |
Correct |
160 ms |
27516 KB |
Output is correct |
39 |
Correct |
152 ms |
27464 KB |
Output is correct |
40 |
Correct |
155 ms |
27448 KB |
Output is correct |
41 |
Correct |
156 ms |
27448 KB |
Output is correct |
42 |
Correct |
163 ms |
27512 KB |
Output is correct |
43 |
Correct |
150 ms |
27524 KB |
Output is correct |
44 |
Correct |
168 ms |
27464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
27396 KB |
Output is correct |
2 |
Correct |
162 ms |
27480 KB |
Output is correct |
3 |
Correct |
158 ms |
27564 KB |
Output is correct |
4 |
Correct |
143 ms |
27488 KB |
Output is correct |
5 |
Correct |
147 ms |
27732 KB |
Output is correct |
6 |
Correct |
140 ms |
27488 KB |
Output is correct |
7 |
Correct |
147 ms |
27444 KB |
Output is correct |
8 |
Correct |
147 ms |
27532 KB |
Output is correct |
9 |
Correct |
155 ms |
27528 KB |
Output is correct |
10 |
Correct |
152 ms |
27636 KB |
Output is correct |
11 |
Correct |
148 ms |
27500 KB |
Output is correct |
12 |
Correct |
148 ms |
27480 KB |
Output is correct |
13 |
Correct |
154 ms |
27460 KB |
Output is correct |
14 |
Correct |
148 ms |
27432 KB |
Output is correct |
15 |
Correct |
155 ms |
27444 KB |
Output is correct |
16 |
Correct |
155 ms |
27536 KB |
Output is correct |
17 |
Correct |
152 ms |
27500 KB |
Output is correct |
18 |
Correct |
156 ms |
27524 KB |
Output is correct |
19 |
Correct |
472 ms |
33052 KB |
Output is correct |
20 |
Correct |
404 ms |
33004 KB |
Output is correct |
21 |
Correct |
342 ms |
32576 KB |
Output is correct |
22 |
Correct |
318 ms |
32060 KB |
Output is correct |
23 |
Correct |
197 ms |
27840 KB |
Output is correct |
24 |
Correct |
186 ms |
27708 KB |
Output is correct |
25 |
Correct |
355 ms |
32956 KB |
Output is correct |
26 |
Correct |
359 ms |
32936 KB |
Output is correct |
27 |
Correct |
406 ms |
32992 KB |
Output is correct |
28 |
Correct |
430 ms |
33072 KB |
Output is correct |
29 |
Correct |
390 ms |
32748 KB |
Output is correct |
30 |
Correct |
202 ms |
27736 KB |
Output is correct |
31 |
Correct |
377 ms |
33056 KB |
Output is correct |
32 |
Correct |
399 ms |
32556 KB |
Output is correct |
33 |
Correct |
196 ms |
27740 KB |
Output is correct |
34 |
Correct |
395 ms |
33132 KB |
Output is correct |
35 |
Correct |
297 ms |
31536 KB |
Output is correct |
36 |
Correct |
189 ms |
27812 KB |
Output is correct |
37 |
Correct |
188 ms |
27712 KB |
Output is correct |
38 |
Correct |
380 ms |
32948 KB |
Output is correct |
39 |
Correct |
234 ms |
32936 KB |
Output is correct |
40 |
Correct |
299 ms |
31028 KB |
Output is correct |
41 |
Correct |
535 ms |
33364 KB |
Output is correct |
42 |
Correct |
220 ms |
33176 KB |
Output is correct |
43 |
Correct |
153 ms |
27416 KB |
Output is correct |
44 |
Correct |
161 ms |
27432 KB |
Output is correct |
45 |
Correct |
151 ms |
27548 KB |
Output is correct |
46 |
Correct |
148 ms |
27436 KB |
Output is correct |
47 |
Correct |
150 ms |
27588 KB |
Output is correct |
48 |
Correct |
158 ms |
27500 KB |
Output is correct |
49 |
Correct |
148 ms |
27464 KB |
Output is correct |
50 |
Correct |
165 ms |
27480 KB |
Output is correct |
51 |
Correct |
148 ms |
27448 KB |
Output is correct |
52 |
Correct |
154 ms |
27380 KB |
Output is correct |
53 |
Correct |
150 ms |
27460 KB |
Output is correct |
54 |
Correct |
143 ms |
27460 KB |
Output is correct |
55 |
Correct |
150 ms |
27460 KB |
Output is correct |
56 |
Correct |
167 ms |
27464 KB |
Output is correct |
57 |
Correct |
165 ms |
27424 KB |
Output is correct |
58 |
Correct |
147 ms |
27472 KB |
Output is correct |
59 |
Correct |
156 ms |
27464 KB |
Output is correct |
60 |
Correct |
157 ms |
27532 KB |
Output is correct |
61 |
Correct |
157 ms |
27444 KB |
Output is correct |
62 |
Correct |
160 ms |
27516 KB |
Output is correct |
63 |
Correct |
152 ms |
27464 KB |
Output is correct |
64 |
Correct |
155 ms |
27448 KB |
Output is correct |
65 |
Correct |
156 ms |
27448 KB |
Output is correct |
66 |
Correct |
163 ms |
27512 KB |
Output is correct |
67 |
Correct |
150 ms |
27524 KB |
Output is correct |
68 |
Correct |
168 ms |
27464 KB |
Output is correct |
69 |
Correct |
460 ms |
31972 KB |
Output is correct |
70 |
Correct |
423 ms |
32896 KB |
Output is correct |
71 |
Correct |
195 ms |
27732 KB |
Output is correct |
72 |
Correct |
194 ms |
27884 KB |
Output is correct |
73 |
Correct |
191 ms |
27752 KB |
Output is correct |
74 |
Correct |
343 ms |
32056 KB |
Output is correct |
75 |
Correct |
190 ms |
27728 KB |
Output is correct |
76 |
Correct |
365 ms |
32924 KB |
Output is correct |
77 |
Correct |
380 ms |
31992 KB |
Output is correct |
78 |
Correct |
194 ms |
27848 KB |
Output is correct |
79 |
Correct |
189 ms |
27716 KB |
Output is correct |
80 |
Correct |
326 ms |
31288 KB |
Output is correct |
81 |
Correct |
190 ms |
27808 KB |
Output is correct |
82 |
Correct |
355 ms |
32944 KB |
Output is correct |
83 |
Correct |
375 ms |
32744 KB |
Output is correct |
84 |
Correct |
206 ms |
27708 KB |
Output is correct |
85 |
Correct |
200 ms |
27892 KB |
Output is correct |
86 |
Correct |
388 ms |
31604 KB |
Output is correct |
87 |
Correct |
428 ms |
33016 KB |
Output is correct |
88 |
Correct |
203 ms |
27776 KB |
Output is correct |
89 |
Correct |
446 ms |
32264 KB |
Output is correct |
90 |
Correct |
418 ms |
32912 KB |
Output is correct |
91 |
Correct |
217 ms |
27740 KB |
Output is correct |
92 |
Correct |
338 ms |
31604 KB |
Output is correct |
93 |
Correct |
196 ms |
27752 KB |
Output is correct |
94 |
Correct |
221 ms |
27748 KB |
Output is correct |
95 |
Correct |
199 ms |
27716 KB |
Output is correct |
96 |
Correct |
415 ms |
32988 KB |
Output is correct |
97 |
Correct |
255 ms |
32988 KB |
Output is correct |
98 |
Correct |
347 ms |
31108 KB |
Output is correct |
99 |
Correct |
588 ms |
33100 KB |
Output is correct |
100 |
Correct |
248 ms |
33168 KB |
Output is correct |