#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
using namespace std;
const ll inf=1e9+7,mxn=2e5+5,B=17;
vector<string>ans;
int n;string s[3];
map<string,int>mp;
int sz;
string cal(string a,string b,string rs=""){
for(int i=0;i<n;i++){
if(a[i]==b[i])rs+=a[i];
else rs+=char('J'+'O'+'I'-a[i]-b[i]);
}return rs;
}int c[200];
ll qs[mxn]{0},pw[mxn]{0},qp[mxn]{0};
struct node{
ll tt,sz;
node operator+(node b){
return node{(tt+(b.tt*pw[sz])%inf)%inf,sz+b.sz};
}
}t[4*mxn];string t0;
int lz[4*mxn];
void push(int i,int l,int r){
if(lz[i]!=-1){
t[i].tt=lz[i]*qp[t[i].sz];
if(l<r)lz[2*i]=lz[i],lz[2*i+1]=lz[i];
lz[i]=-1;
}
}
void build(int i,int l,int r){
lz[i]=-1;
if(l==r)return void(t[i]={c[t0[l-1]],1});
int m=(l+r)>>1;build(2*i,l,m);build(2*i+1,m+1,r);
t[i]=t[2*i]+t[2*i+1];
}void check(){
for(int i=0;i<ans.size();i++){if(((t[1].tt)%inf+inf)%inf==(qs[i]%inf+inf)%inf){cout<<"Yes\n";return;}}
cout<<"No\n";
}
void upd(int i,int l,int r,int tl,int tr,int v){
push(i,l,r);
if(r<tl||l>tr)return;
if(r<=tr&&l>=tl){
lz[i]=v;push(i,l,r);return;
}int m=(l+r)>>1;upd(2*i,l,m,tl,tr,v);upd(2*i+1,m+1,r,tl,tr,v);
t[i]=t[2*i]+t[2*i+1];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>s[0]>>s[1]>>s[2];mp[s[0]]=mp[s[1]]=mp[s[2]]=1;pw[0]=1;
for(int i=1;i<=n;i++)pw[i]=(pw[i-1]*B)%inf;qp[0]=0;
for(int i=1;i<=n;i++)qp[i]=(qp[i-1]+pw[i-1])%inf;
ans.pb(s[0]);ans.pb(s[1]);ans.pb(s[2]);
for(int i=0;i<ans.size();i++){
for(int j=0;j<3;j++){
string rs=cal(ans[i],ans[j]);
if(mp.find(rs)==mp.end())mp[rs]=1,ans.pb(rs);
}
}sz=ans.size();c['J']=0,c['O']=1,c['I']=2;
for(int i=0;i<sz;i++){
for(int j=0;j<n;j++){
qs[i]+=c[ans[i][j]]*pw[j];
qs[i]%=inf;
}
}int q;cin>>q>>t0;build(1,1,n);check();
while(q--){
int l,r;char x;cin>>l>>r>>x;
upd(1,1,n,l,r,c[x]);check();
}
}
Compilation message
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:42:40: warning: array subscript has type 'char' [-Wchar-subscripts]
42 | if(l==r)return void(t[i]={c[t0[l-1]],1});
| ^
Main.cpp: In function 'void check()':
Main.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<ans.size();i++){if(((t[1].tt)%inf+inf)%inf==(qs[i]%inf+inf)%inf){cout<<"Yes\n";return;}}
| ~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:60:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
60 | for(int i=1;i<=n;i++)pw[i]=(pw[i-1]*B)%inf;qp[0]=0;
| ^~~
Main.cpp:60:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
60 | for(int i=1;i<=n;i++)pw[i]=(pw[i-1]*B)%inf;qp[0]=0;
| ^~
Main.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
Main.cpp:71:31: warning: array subscript has type 'char' [-Wchar-subscripts]
71 | qs[i]+=c[ans[i][j]]*pw[j];
| ^
Main.cpp:77:25: warning: array subscript has type 'char' [-Wchar-subscripts]
77 | upd(1,1,n,l,r,c[x]);check();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2128 KB |
Output is correct |
2 |
Correct |
60 ms |
2128 KB |
Output is correct |
3 |
Correct |
64 ms |
2124 KB |
Output is correct |
4 |
Correct |
49 ms |
2072 KB |
Output is correct |
5 |
Correct |
49 ms |
2156 KB |
Output is correct |
6 |
Correct |
50 ms |
2224 KB |
Output is correct |
7 |
Correct |
51 ms |
2264 KB |
Output is correct |
8 |
Correct |
55 ms |
2128 KB |
Output is correct |
9 |
Correct |
53 ms |
2308 KB |
Output is correct |
10 |
Correct |
53 ms |
2136 KB |
Output is correct |
11 |
Correct |
53 ms |
2140 KB |
Output is correct |
12 |
Correct |
55 ms |
2360 KB |
Output is correct |
13 |
Correct |
55 ms |
2260 KB |
Output is correct |
14 |
Correct |
53 ms |
2132 KB |
Output is correct |
15 |
Correct |
58 ms |
2132 KB |
Output is correct |
16 |
Correct |
66 ms |
2132 KB |
Output is correct |
17 |
Correct |
52 ms |
2544 KB |
Output is correct |
18 |
Correct |
57 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2128 KB |
Output is correct |
2 |
Correct |
60 ms |
2128 KB |
Output is correct |
3 |
Correct |
64 ms |
2124 KB |
Output is correct |
4 |
Correct |
49 ms |
2072 KB |
Output is correct |
5 |
Correct |
49 ms |
2156 KB |
Output is correct |
6 |
Correct |
50 ms |
2224 KB |
Output is correct |
7 |
Correct |
51 ms |
2264 KB |
Output is correct |
8 |
Correct |
55 ms |
2128 KB |
Output is correct |
9 |
Correct |
53 ms |
2308 KB |
Output is correct |
10 |
Correct |
53 ms |
2136 KB |
Output is correct |
11 |
Correct |
53 ms |
2140 KB |
Output is correct |
12 |
Correct |
55 ms |
2360 KB |
Output is correct |
13 |
Correct |
55 ms |
2260 KB |
Output is correct |
14 |
Correct |
53 ms |
2132 KB |
Output is correct |
15 |
Correct |
58 ms |
2132 KB |
Output is correct |
16 |
Correct |
66 ms |
2132 KB |
Output is correct |
17 |
Correct |
52 ms |
2544 KB |
Output is correct |
18 |
Correct |
57 ms |
2132 KB |
Output is correct |
19 |
Correct |
189 ms |
18452 KB |
Output is correct |
20 |
Correct |
187 ms |
18528 KB |
Output is correct |
21 |
Correct |
139 ms |
18308 KB |
Output is correct |
22 |
Correct |
131 ms |
17456 KB |
Output is correct |
23 |
Correct |
91 ms |
3664 KB |
Output is correct |
24 |
Correct |
91 ms |
3640 KB |
Output is correct |
25 |
Correct |
136 ms |
18496 KB |
Output is correct |
26 |
Correct |
147 ms |
18568 KB |
Output is correct |
27 |
Correct |
152 ms |
18196 KB |
Output is correct |
28 |
Correct |
157 ms |
18196 KB |
Output is correct |
29 |
Correct |
145 ms |
18192 KB |
Output is correct |
30 |
Correct |
91 ms |
3412 KB |
Output is correct |
31 |
Correct |
151 ms |
18424 KB |
Output is correct |
32 |
Correct |
139 ms |
17792 KB |
Output is correct |
33 |
Correct |
86 ms |
3396 KB |
Output is correct |
34 |
Correct |
144 ms |
18144 KB |
Output is correct |
35 |
Correct |
115 ms |
16592 KB |
Output is correct |
36 |
Correct |
86 ms |
4056 KB |
Output is correct |
37 |
Correct |
84 ms |
4180 KB |
Output is correct |
38 |
Correct |
156 ms |
19428 KB |
Output is correct |
39 |
Correct |
116 ms |
19112 KB |
Output is correct |
40 |
Correct |
125 ms |
12160 KB |
Output is correct |
41 |
Correct |
199 ms |
19524 KB |
Output is correct |
42 |
Correct |
49 ms |
19004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2128 KB |
Output is correct |
2 |
Correct |
60 ms |
2128 KB |
Output is correct |
3 |
Correct |
64 ms |
2124 KB |
Output is correct |
4 |
Correct |
49 ms |
2072 KB |
Output is correct |
5 |
Correct |
49 ms |
2156 KB |
Output is correct |
6 |
Correct |
50 ms |
2224 KB |
Output is correct |
7 |
Correct |
51 ms |
2264 KB |
Output is correct |
8 |
Correct |
55 ms |
2128 KB |
Output is correct |
9 |
Correct |
53 ms |
2308 KB |
Output is correct |
10 |
Correct |
53 ms |
2136 KB |
Output is correct |
11 |
Correct |
53 ms |
2140 KB |
Output is correct |
12 |
Correct |
55 ms |
2360 KB |
Output is correct |
13 |
Correct |
55 ms |
2260 KB |
Output is correct |
14 |
Correct |
53 ms |
2132 KB |
Output is correct |
15 |
Correct |
58 ms |
2132 KB |
Output is correct |
16 |
Correct |
66 ms |
2132 KB |
Output is correct |
17 |
Correct |
52 ms |
2544 KB |
Output is correct |
18 |
Correct |
57 ms |
2132 KB |
Output is correct |
19 |
Correct |
58 ms |
2388 KB |
Output is correct |
20 |
Correct |
61 ms |
2384 KB |
Output is correct |
21 |
Correct |
53 ms |
2384 KB |
Output is correct |
22 |
Correct |
45 ms |
2388 KB |
Output is correct |
23 |
Correct |
64 ms |
2388 KB |
Output is correct |
24 |
Correct |
49 ms |
2336 KB |
Output is correct |
25 |
Correct |
54 ms |
2384 KB |
Output is correct |
26 |
Correct |
49 ms |
2324 KB |
Output is correct |
27 |
Correct |
55 ms |
2380 KB |
Output is correct |
28 |
Correct |
47 ms |
2384 KB |
Output is correct |
29 |
Correct |
58 ms |
2472 KB |
Output is correct |
30 |
Correct |
46 ms |
2388 KB |
Output is correct |
31 |
Correct |
53 ms |
2384 KB |
Output is correct |
32 |
Correct |
55 ms |
2388 KB |
Output is correct |
33 |
Correct |
57 ms |
2392 KB |
Output is correct |
34 |
Correct |
56 ms |
2388 KB |
Output is correct |
35 |
Correct |
56 ms |
2388 KB |
Output is correct |
36 |
Correct |
58 ms |
2388 KB |
Output is correct |
37 |
Correct |
54 ms |
2600 KB |
Output is correct |
38 |
Correct |
56 ms |
2388 KB |
Output is correct |
39 |
Correct |
55 ms |
2384 KB |
Output is correct |
40 |
Correct |
55 ms |
2388 KB |
Output is correct |
41 |
Correct |
58 ms |
2388 KB |
Output is correct |
42 |
Correct |
56 ms |
2664 KB |
Output is correct |
43 |
Correct |
54 ms |
2376 KB |
Output is correct |
44 |
Correct |
56 ms |
2604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2128 KB |
Output is correct |
2 |
Correct |
60 ms |
2128 KB |
Output is correct |
3 |
Correct |
64 ms |
2124 KB |
Output is correct |
4 |
Correct |
49 ms |
2072 KB |
Output is correct |
5 |
Correct |
49 ms |
2156 KB |
Output is correct |
6 |
Correct |
50 ms |
2224 KB |
Output is correct |
7 |
Correct |
51 ms |
2264 KB |
Output is correct |
8 |
Correct |
55 ms |
2128 KB |
Output is correct |
9 |
Correct |
53 ms |
2308 KB |
Output is correct |
10 |
Correct |
53 ms |
2136 KB |
Output is correct |
11 |
Correct |
53 ms |
2140 KB |
Output is correct |
12 |
Correct |
55 ms |
2360 KB |
Output is correct |
13 |
Correct |
55 ms |
2260 KB |
Output is correct |
14 |
Correct |
53 ms |
2132 KB |
Output is correct |
15 |
Correct |
58 ms |
2132 KB |
Output is correct |
16 |
Correct |
66 ms |
2132 KB |
Output is correct |
17 |
Correct |
52 ms |
2544 KB |
Output is correct |
18 |
Correct |
57 ms |
2132 KB |
Output is correct |
19 |
Correct |
189 ms |
18452 KB |
Output is correct |
20 |
Correct |
187 ms |
18528 KB |
Output is correct |
21 |
Correct |
139 ms |
18308 KB |
Output is correct |
22 |
Correct |
131 ms |
17456 KB |
Output is correct |
23 |
Correct |
91 ms |
3664 KB |
Output is correct |
24 |
Correct |
91 ms |
3640 KB |
Output is correct |
25 |
Correct |
136 ms |
18496 KB |
Output is correct |
26 |
Correct |
147 ms |
18568 KB |
Output is correct |
27 |
Correct |
152 ms |
18196 KB |
Output is correct |
28 |
Correct |
157 ms |
18196 KB |
Output is correct |
29 |
Correct |
145 ms |
18192 KB |
Output is correct |
30 |
Correct |
91 ms |
3412 KB |
Output is correct |
31 |
Correct |
151 ms |
18424 KB |
Output is correct |
32 |
Correct |
139 ms |
17792 KB |
Output is correct |
33 |
Correct |
86 ms |
3396 KB |
Output is correct |
34 |
Correct |
144 ms |
18144 KB |
Output is correct |
35 |
Correct |
115 ms |
16592 KB |
Output is correct |
36 |
Correct |
86 ms |
4056 KB |
Output is correct |
37 |
Correct |
84 ms |
4180 KB |
Output is correct |
38 |
Correct |
156 ms |
19428 KB |
Output is correct |
39 |
Correct |
116 ms |
19112 KB |
Output is correct |
40 |
Correct |
125 ms |
12160 KB |
Output is correct |
41 |
Correct |
199 ms |
19524 KB |
Output is correct |
42 |
Correct |
49 ms |
19004 KB |
Output is correct |
43 |
Correct |
58 ms |
2388 KB |
Output is correct |
44 |
Correct |
61 ms |
2384 KB |
Output is correct |
45 |
Correct |
53 ms |
2384 KB |
Output is correct |
46 |
Correct |
45 ms |
2388 KB |
Output is correct |
47 |
Correct |
64 ms |
2388 KB |
Output is correct |
48 |
Correct |
49 ms |
2336 KB |
Output is correct |
49 |
Correct |
54 ms |
2384 KB |
Output is correct |
50 |
Correct |
49 ms |
2324 KB |
Output is correct |
51 |
Correct |
55 ms |
2380 KB |
Output is correct |
52 |
Correct |
47 ms |
2384 KB |
Output is correct |
53 |
Correct |
58 ms |
2472 KB |
Output is correct |
54 |
Correct |
46 ms |
2388 KB |
Output is correct |
55 |
Correct |
53 ms |
2384 KB |
Output is correct |
56 |
Correct |
55 ms |
2388 KB |
Output is correct |
57 |
Correct |
57 ms |
2392 KB |
Output is correct |
58 |
Correct |
56 ms |
2388 KB |
Output is correct |
59 |
Correct |
56 ms |
2388 KB |
Output is correct |
60 |
Correct |
58 ms |
2388 KB |
Output is correct |
61 |
Correct |
54 ms |
2600 KB |
Output is correct |
62 |
Correct |
56 ms |
2388 KB |
Output is correct |
63 |
Correct |
55 ms |
2384 KB |
Output is correct |
64 |
Correct |
55 ms |
2388 KB |
Output is correct |
65 |
Correct |
58 ms |
2388 KB |
Output is correct |
66 |
Correct |
56 ms |
2664 KB |
Output is correct |
67 |
Correct |
54 ms |
2376 KB |
Output is correct |
68 |
Correct |
56 ms |
2604 KB |
Output is correct |
69 |
Correct |
215 ms |
20436 KB |
Output is correct |
70 |
Correct |
210 ms |
22120 KB |
Output is correct |
71 |
Correct |
89 ms |
4192 KB |
Output is correct |
72 |
Correct |
87 ms |
4176 KB |
Output is correct |
73 |
Correct |
84 ms |
4180 KB |
Output is correct |
74 |
Correct |
127 ms |
19176 KB |
Output is correct |
75 |
Correct |
83 ms |
4244 KB |
Output is correct |
76 |
Correct |
139 ms |
20308 KB |
Output is correct |
77 |
Correct |
124 ms |
19044 KB |
Output is correct |
78 |
Correct |
96 ms |
4180 KB |
Output is correct |
79 |
Correct |
89 ms |
4180 KB |
Output is correct |
80 |
Correct |
165 ms |
19872 KB |
Output is correct |
81 |
Correct |
91 ms |
4436 KB |
Output is correct |
82 |
Correct |
177 ms |
22748 KB |
Output is correct |
83 |
Correct |
184 ms |
22208 KB |
Output is correct |
84 |
Correct |
95 ms |
4400 KB |
Output is correct |
85 |
Correct |
94 ms |
4432 KB |
Output is correct |
86 |
Correct |
166 ms |
20320 KB |
Output is correct |
87 |
Correct |
190 ms |
22656 KB |
Output is correct |
88 |
Correct |
98 ms |
4444 KB |
Output is correct |
89 |
Correct |
159 ms |
21496 KB |
Output is correct |
90 |
Correct |
190 ms |
22612 KB |
Output is correct |
91 |
Correct |
105 ms |
4264 KB |
Output is correct |
92 |
Correct |
179 ms |
20240 KB |
Output is correct |
93 |
Correct |
90 ms |
4432 KB |
Output is correct |
94 |
Correct |
87 ms |
4344 KB |
Output is correct |
95 |
Correct |
99 ms |
4252 KB |
Output is correct |
96 |
Correct |
163 ms |
19552 KB |
Output is correct |
97 |
Correct |
142 ms |
22840 KB |
Output is correct |
98 |
Correct |
139 ms |
14656 KB |
Output is correct |
99 |
Correct |
241 ms |
22900 KB |
Output is correct |
100 |
Correct |
78 ms |
22136 KB |
Output is correct |