//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo aa[200001];
llo bb[200001];
llo cc[200001];
llo dd[200001];
llo ac=2329923;
const llo mod=1e9+7;
llo bc=54959459;
const llo mod2=1e9+7;
llo pre[200001];
llo pre2[200001];
pair<llo,llo> tree[200001*4];
pair<llo,llo> tree2[200001*4];
llo lazy[4*200001];
void push(llo no,llo l,llo r){
if(lazy[no]>0){
// cout<<l<<".."<<r<<".."<<lazy[no]<<".."<<tree2[no].a<<",,"<<tree2[no].b<<endl;
tree[no].a=(tree2[no].a*lazy[no])%mod;
tree[no].b=(tree2[no].b*lazy[no])%mod2;
//cout<<tree[no].a<<"::"<<tree[no].b<<endl;
if(l<r){
lazy[no*2+1]=lazy[no];
lazy[no*2+2]=lazy[no];
}
lazy[no]=0;
}
}
void build(llo no,llo l,llo r){
if(l==r){
tree[no]={((dd[l]+1)*pre[l])%mod,((dd[l]+1)*pre2[l])%mod2};
tree2[no]={pre[l],pre2[l]};
}
else{
llo mid=(l+r)/2;
build(no*2+1,l,mid);
build(no*2+2,mid+1,r);
tree[no].a=(tree[no*2+1].a+tree[no*2+2].a)%mod;
tree[no].b=(tree[no*2+1].b+tree[no*2+2].b)%mod2;
tree2[no].a=(tree2[no*2+1].a+tree2[no*2+2].a)%mod;
tree2[no].b=(tree2[no*2+1].b+tree2[no*2+2].b)%mod2;
}
}
void update(llo no,llo l,llo r,llo aa,llo bb,llo i){
push(no,l,r);
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
//cout<<aa<<":"<<bb<<endl;
lazy[no]=i+1;
push(no,l,r);
}
else{
llo mid=(l+r)/2;
update(no*2+1,l,mid,aa,bb,i);
update(no*2+2,mid+1,r,aa,bb,i);
tree[no].a=(tree[no*2+1].a+tree[no*2+2].a)%mod;
tree[no].b=(tree[no*2+1].b+tree[no*2+2].b)%mod2;
}
}
/*void solve(int no,int l,int r){
//solve(n,l,r);
cout<<l<<":"<<r<<":"<<tree[no].a<<endl;
if(l==r){
}
else{
llo mid=(l+r)/2;
solve(no*2+1,l,mid);
solve(no*2+2,mid+1,r);
tree[no].a=(tree[no*2+1].a+tree[no*2+2].a)%mod;
tree[no].b=(tree[no*2+1].b+tree[no*2+2].b)%mod2;
}
}*/
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n;
cin>>n;
pre[0]=1;
pre2[0]=1;
for(llo i=1;i<=n;i++){
pre[i]=(pre[i-1]*ac)%mod;
pre2[i]=(pre2[i-1]*bc)%mod2;
}
/*llo kk=0;
for(llo i=0;i<n;i++){
kk=(kk+pre2[i])%mod2;
}
cout<<kk<<endl;*/
string aa2,bb2,cc2;
cin>>aa2>>bb2>>cc2;
for(llo i=0;i<n;i++){
char s=aa2[i];
if(s=='J'){
aa[i]=0;
}
else if(s=='O'){
aa[i]=1;
}
else{
aa[i]=2;
}
}
for(llo i=0;i<n;i++){
char s=cc2[i];
if(s=='J'){
cc[i]=0;
}
else if(s=='O'){
cc[i]=1;
}
else{
cc[i]=2;
}
}
for(llo i=0;i<n;i++){
char s=bb2[i];
if(s=='J'){
bb[i]=0;
}
else if(s=='O'){
bb[i]=1;
}
else{
bb[i]=2;
}
}
//for(llo i=0;i<3;i++){
//for(llo j=0;j<3;j++){
// for(llo k=0;k<3;k++){
/*if(i==0 and j==0 and k==0){
continue;
}*/
set<vector<llo>> ss;
ss.insert({1,0,0});
ss.insert({0,1,0});
ss.insert({0,0,1});
while(ss.size()){
vector<vector<llo>> tt;
for(auto jj:ss){
tt.pb(jj);
}
for(auto ii:tt){
for(auto jj:tt){
vector<llo> kk;
for(llo k=0;k<3;k++){
kk.pb((-ii[k]-jj[k]+9)%3);
}
if(ss.find(kk)==ss.end()){
ss.insert(kk);
break;
}
}
if(tt.size()<ss.size()){
break;
}
}
if(tt.size()==ss.size()){
break;
}
}
/*for(auto j:ss){
for(auto i:j){
cout<<i<<",";
}
cout<<endl;
}*/
//}
//}
//}
set<pair<llo,llo>> xx;
for(auto j:ss){
llo su=0;
llo su2=0;
for(llo i=0;i<n;i++){
llo cur=(aa[i]*j[0]+bb[i]*j[1]+cc[i]*j[2])%3;
su=(su+(pre[i])*(cur+1))%mod;
su2=(su2+(pre2[i])*(cur+1))%mod2;
//cout<<cur<<",";
}
//cout<<endl;
xx.insert({su,su2});
}
llo q;
cin>>q;
string dd2;
cin>>dd2;
for(llo i=0;i<n;i++){
char s=dd2[i];
if(s=='J'){
dd[i]=0;
}
else if(s=='O'){
dd[i]=1;
}
else{
dd[i]=2;
}
//cout<<dd[i]<<":";
}
//cout<<endl;
build(0,0,n-1);
for(llo i=0;i<=q;i++){
if(xx.find(tree[0])==xx.end()){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
}
if(i<q){
llo l,r;
char s;
cin>>l>>r>>s;
l--;
r--;
llo cur=0;
if(s=='J'){
cur=0;
}
else if(s=='O'){
cur=1;
}
else{
cur=2;
}
update(0,0,n-1,l,r,cur);
}
//solve(0,0,n-1);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
836 KB |
Output is correct |
2 |
Correct |
113 ms |
976 KB |
Output is correct |
3 |
Correct |
109 ms |
900 KB |
Output is correct |
4 |
Correct |
89 ms |
964 KB |
Output is correct |
5 |
Correct |
91 ms |
852 KB |
Output is correct |
6 |
Correct |
88 ms |
896 KB |
Output is correct |
7 |
Correct |
91 ms |
960 KB |
Output is correct |
8 |
Correct |
95 ms |
944 KB |
Output is correct |
9 |
Correct |
92 ms |
900 KB |
Output is correct |
10 |
Correct |
96 ms |
876 KB |
Output is correct |
11 |
Correct |
95 ms |
944 KB |
Output is correct |
12 |
Correct |
99 ms |
984 KB |
Output is correct |
13 |
Correct |
98 ms |
920 KB |
Output is correct |
14 |
Correct |
98 ms |
904 KB |
Output is correct |
15 |
Correct |
93 ms |
916 KB |
Output is correct |
16 |
Correct |
95 ms |
964 KB |
Output is correct |
17 |
Correct |
100 ms |
1068 KB |
Output is correct |
18 |
Correct |
120 ms |
948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
836 KB |
Output is correct |
2 |
Correct |
113 ms |
976 KB |
Output is correct |
3 |
Correct |
109 ms |
900 KB |
Output is correct |
4 |
Correct |
89 ms |
964 KB |
Output is correct |
5 |
Correct |
91 ms |
852 KB |
Output is correct |
6 |
Correct |
88 ms |
896 KB |
Output is correct |
7 |
Correct |
91 ms |
960 KB |
Output is correct |
8 |
Correct |
95 ms |
944 KB |
Output is correct |
9 |
Correct |
92 ms |
900 KB |
Output is correct |
10 |
Correct |
96 ms |
876 KB |
Output is correct |
11 |
Correct |
95 ms |
944 KB |
Output is correct |
12 |
Correct |
99 ms |
984 KB |
Output is correct |
13 |
Correct |
98 ms |
920 KB |
Output is correct |
14 |
Correct |
98 ms |
904 KB |
Output is correct |
15 |
Correct |
93 ms |
916 KB |
Output is correct |
16 |
Correct |
95 ms |
964 KB |
Output is correct |
17 |
Correct |
100 ms |
1068 KB |
Output is correct |
18 |
Correct |
120 ms |
948 KB |
Output is correct |
19 |
Correct |
427 ms |
31876 KB |
Output is correct |
20 |
Correct |
375 ms |
28512 KB |
Output is correct |
21 |
Correct |
354 ms |
31096 KB |
Output is correct |
22 |
Correct |
337 ms |
30292 KB |
Output is correct |
23 |
Correct |
175 ms |
2740 KB |
Output is correct |
24 |
Correct |
156 ms |
2864 KB |
Output is correct |
25 |
Correct |
284 ms |
31764 KB |
Output is correct |
26 |
Correct |
335 ms |
31732 KB |
Output is correct |
27 |
Correct |
438 ms |
31760 KB |
Output is correct |
28 |
Correct |
387 ms |
31740 KB |
Output is correct |
29 |
Correct |
367 ms |
31504 KB |
Output is correct |
30 |
Correct |
179 ms |
2760 KB |
Output is correct |
31 |
Correct |
373 ms |
31752 KB |
Output is correct |
32 |
Correct |
375 ms |
30872 KB |
Output is correct |
33 |
Correct |
165 ms |
2716 KB |
Output is correct |
34 |
Correct |
377 ms |
31720 KB |
Output is correct |
35 |
Correct |
259 ms |
29088 KB |
Output is correct |
36 |
Correct |
153 ms |
2712 KB |
Output is correct |
37 |
Correct |
167 ms |
2720 KB |
Output is correct |
38 |
Correct |
357 ms |
28468 KB |
Output is correct |
39 |
Correct |
187 ms |
27620 KB |
Output is correct |
40 |
Correct |
256 ms |
17964 KB |
Output is correct |
41 |
Correct |
490 ms |
31896 KB |
Output is correct |
42 |
Correct |
96 ms |
27768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
836 KB |
Output is correct |
2 |
Correct |
113 ms |
976 KB |
Output is correct |
3 |
Correct |
109 ms |
900 KB |
Output is correct |
4 |
Correct |
89 ms |
964 KB |
Output is correct |
5 |
Correct |
91 ms |
852 KB |
Output is correct |
6 |
Correct |
88 ms |
896 KB |
Output is correct |
7 |
Correct |
91 ms |
960 KB |
Output is correct |
8 |
Correct |
95 ms |
944 KB |
Output is correct |
9 |
Correct |
92 ms |
900 KB |
Output is correct |
10 |
Correct |
96 ms |
876 KB |
Output is correct |
11 |
Correct |
95 ms |
944 KB |
Output is correct |
12 |
Correct |
99 ms |
984 KB |
Output is correct |
13 |
Correct |
98 ms |
920 KB |
Output is correct |
14 |
Correct |
98 ms |
904 KB |
Output is correct |
15 |
Correct |
93 ms |
916 KB |
Output is correct |
16 |
Correct |
95 ms |
964 KB |
Output is correct |
17 |
Correct |
100 ms |
1068 KB |
Output is correct |
18 |
Correct |
120 ms |
948 KB |
Output is correct |
19 |
Correct |
119 ms |
892 KB |
Output is correct |
20 |
Correct |
114 ms |
944 KB |
Output is correct |
21 |
Correct |
95 ms |
980 KB |
Output is correct |
22 |
Correct |
84 ms |
828 KB |
Output is correct |
23 |
Correct |
109 ms |
940 KB |
Output is correct |
24 |
Correct |
93 ms |
928 KB |
Output is correct |
25 |
Correct |
115 ms |
868 KB |
Output is correct |
26 |
Correct |
93 ms |
936 KB |
Output is correct |
27 |
Correct |
93 ms |
932 KB |
Output is correct |
28 |
Correct |
89 ms |
904 KB |
Output is correct |
29 |
Correct |
111 ms |
952 KB |
Output is correct |
30 |
Correct |
85 ms |
896 KB |
Output is correct |
31 |
Correct |
96 ms |
956 KB |
Output is correct |
32 |
Correct |
95 ms |
908 KB |
Output is correct |
33 |
Correct |
101 ms |
936 KB |
Output is correct |
34 |
Correct |
92 ms |
844 KB |
Output is correct |
35 |
Correct |
113 ms |
908 KB |
Output is correct |
36 |
Correct |
106 ms |
920 KB |
Output is correct |
37 |
Correct |
110 ms |
964 KB |
Output is correct |
38 |
Correct |
106 ms |
968 KB |
Output is correct |
39 |
Correct |
97 ms |
1060 KB |
Output is correct |
40 |
Correct |
97 ms |
904 KB |
Output is correct |
41 |
Correct |
97 ms |
920 KB |
Output is correct |
42 |
Correct |
103 ms |
904 KB |
Output is correct |
43 |
Correct |
128 ms |
984 KB |
Output is correct |
44 |
Correct |
101 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
836 KB |
Output is correct |
2 |
Correct |
113 ms |
976 KB |
Output is correct |
3 |
Correct |
109 ms |
900 KB |
Output is correct |
4 |
Correct |
89 ms |
964 KB |
Output is correct |
5 |
Correct |
91 ms |
852 KB |
Output is correct |
6 |
Correct |
88 ms |
896 KB |
Output is correct |
7 |
Correct |
91 ms |
960 KB |
Output is correct |
8 |
Correct |
95 ms |
944 KB |
Output is correct |
9 |
Correct |
92 ms |
900 KB |
Output is correct |
10 |
Correct |
96 ms |
876 KB |
Output is correct |
11 |
Correct |
95 ms |
944 KB |
Output is correct |
12 |
Correct |
99 ms |
984 KB |
Output is correct |
13 |
Correct |
98 ms |
920 KB |
Output is correct |
14 |
Correct |
98 ms |
904 KB |
Output is correct |
15 |
Correct |
93 ms |
916 KB |
Output is correct |
16 |
Correct |
95 ms |
964 KB |
Output is correct |
17 |
Correct |
100 ms |
1068 KB |
Output is correct |
18 |
Correct |
120 ms |
948 KB |
Output is correct |
19 |
Correct |
427 ms |
31876 KB |
Output is correct |
20 |
Correct |
375 ms |
28512 KB |
Output is correct |
21 |
Correct |
354 ms |
31096 KB |
Output is correct |
22 |
Correct |
337 ms |
30292 KB |
Output is correct |
23 |
Correct |
175 ms |
2740 KB |
Output is correct |
24 |
Correct |
156 ms |
2864 KB |
Output is correct |
25 |
Correct |
284 ms |
31764 KB |
Output is correct |
26 |
Correct |
335 ms |
31732 KB |
Output is correct |
27 |
Correct |
438 ms |
31760 KB |
Output is correct |
28 |
Correct |
387 ms |
31740 KB |
Output is correct |
29 |
Correct |
367 ms |
31504 KB |
Output is correct |
30 |
Correct |
179 ms |
2760 KB |
Output is correct |
31 |
Correct |
373 ms |
31752 KB |
Output is correct |
32 |
Correct |
375 ms |
30872 KB |
Output is correct |
33 |
Correct |
165 ms |
2716 KB |
Output is correct |
34 |
Correct |
377 ms |
31720 KB |
Output is correct |
35 |
Correct |
259 ms |
29088 KB |
Output is correct |
36 |
Correct |
153 ms |
2712 KB |
Output is correct |
37 |
Correct |
167 ms |
2720 KB |
Output is correct |
38 |
Correct |
357 ms |
28468 KB |
Output is correct |
39 |
Correct |
187 ms |
27620 KB |
Output is correct |
40 |
Correct |
256 ms |
17964 KB |
Output is correct |
41 |
Correct |
490 ms |
31896 KB |
Output is correct |
42 |
Correct |
96 ms |
27768 KB |
Output is correct |
43 |
Correct |
119 ms |
892 KB |
Output is correct |
44 |
Correct |
114 ms |
944 KB |
Output is correct |
45 |
Correct |
95 ms |
980 KB |
Output is correct |
46 |
Correct |
84 ms |
828 KB |
Output is correct |
47 |
Correct |
109 ms |
940 KB |
Output is correct |
48 |
Correct |
93 ms |
928 KB |
Output is correct |
49 |
Correct |
115 ms |
868 KB |
Output is correct |
50 |
Correct |
93 ms |
936 KB |
Output is correct |
51 |
Correct |
93 ms |
932 KB |
Output is correct |
52 |
Correct |
89 ms |
904 KB |
Output is correct |
53 |
Correct |
111 ms |
952 KB |
Output is correct |
54 |
Correct |
85 ms |
896 KB |
Output is correct |
55 |
Correct |
96 ms |
956 KB |
Output is correct |
56 |
Correct |
95 ms |
908 KB |
Output is correct |
57 |
Correct |
101 ms |
936 KB |
Output is correct |
58 |
Correct |
92 ms |
844 KB |
Output is correct |
59 |
Correct |
113 ms |
908 KB |
Output is correct |
60 |
Correct |
106 ms |
920 KB |
Output is correct |
61 |
Correct |
110 ms |
964 KB |
Output is correct |
62 |
Correct |
106 ms |
968 KB |
Output is correct |
63 |
Correct |
97 ms |
1060 KB |
Output is correct |
64 |
Correct |
97 ms |
904 KB |
Output is correct |
65 |
Correct |
97 ms |
920 KB |
Output is correct |
66 |
Correct |
103 ms |
904 KB |
Output is correct |
67 |
Correct |
128 ms |
984 KB |
Output is correct |
68 |
Correct |
101 ms |
952 KB |
Output is correct |
69 |
Correct |
411 ms |
30028 KB |
Output is correct |
70 |
Correct |
379 ms |
28448 KB |
Output is correct |
71 |
Correct |
186 ms |
2696 KB |
Output is correct |
72 |
Correct |
161 ms |
2700 KB |
Output is correct |
73 |
Correct |
163 ms |
2740 KB |
Output is correct |
74 |
Correct |
291 ms |
30124 KB |
Output is correct |
75 |
Correct |
174 ms |
2768 KB |
Output is correct |
76 |
Correct |
313 ms |
31712 KB |
Output is correct |
77 |
Correct |
324 ms |
30172 KB |
Output is correct |
78 |
Correct |
227 ms |
2756 KB |
Output is correct |
79 |
Correct |
169 ms |
2696 KB |
Output is correct |
80 |
Correct |
271 ms |
28704 KB |
Output is correct |
81 |
Correct |
162 ms |
2724 KB |
Output is correct |
82 |
Correct |
301 ms |
31752 KB |
Output is correct |
83 |
Correct |
418 ms |
31060 KB |
Output is correct |
84 |
Correct |
162 ms |
2756 KB |
Output is correct |
85 |
Correct |
207 ms |
2744 KB |
Output is correct |
86 |
Correct |
476 ms |
29208 KB |
Output is correct |
87 |
Correct |
461 ms |
31716 KB |
Output is correct |
88 |
Correct |
206 ms |
2700 KB |
Output is correct |
89 |
Correct |
490 ms |
30504 KB |
Output is correct |
90 |
Correct |
519 ms |
31704 KB |
Output is correct |
91 |
Correct |
199 ms |
2700 KB |
Output is correct |
92 |
Correct |
286 ms |
29144 KB |
Output is correct |
93 |
Correct |
165 ms |
2756 KB |
Output is correct |
94 |
Correct |
168 ms |
2656 KB |
Output is correct |
95 |
Correct |
173 ms |
2740 KB |
Output is correct |
96 |
Correct |
395 ms |
28536 KB |
Output is correct |
97 |
Correct |
251 ms |
27668 KB |
Output is correct |
98 |
Correct |
368 ms |
17992 KB |
Output is correct |
99 |
Correct |
506 ms |
31868 KB |
Output is correct |
100 |
Correct |
92 ms |
27796 KB |
Output is correct |