This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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=123456789,mxn=2e5+5,B=3;
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 (stderr)
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();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |