이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int n,seg[4*N+5],q,po[N],pj[N],pi[N];
char a[N],b[N],lazy[4*N+5];
int build(int node,int l,int r){
lazy[node]='A';
if (l==r) return seg[node]=(a[l]==b[l]);
int mid=(l+r)/2;
return seg[node]=build(node*2,l,mid)+build(node*2+1,mid+1,r);
}
int edit(int node,int l,int r,int lx,int rx,char x){
if (r<lx || l>rx){
if (lazy[node]!='A'){
if (lazy[node]=='O') seg[node]=po[r]-po[l-1];
elif (lazy[node]=='J') seg[node]=pj[r]-pj[l-1];
else seg[node]=pi[r]-pi[l-1];
}return seg[node];
}
if (l>=lx && r<=rx){
lazy[node]=x;
if (lazy[node]=='O') seg[node]=po[r]-po[l-1];
elif (lazy[node]=='J') seg[node]=pj[r]-pj[l-1];
else seg[node]=pi[r]-pi[l-1];
return seg[node];
}int mid=(l+r)/2;
if (lazy[node]!='A'){
lazy[node*2]=lazy[node];
lazy[node*2+1]=lazy[node];
lazy[node]='A';
}return seg[node]=edit(node*2,l,mid,lx,rx,x)+edit(node*2+1,mid+1,r,lx,rx,x);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=0;i<3;i++) for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++){
po[i]=po[i-1],pj[i]=pj[i-1],pi[i]=pi[i-1];
if (a[i]=='J') pj[i]++;
elif (a[i]=='O') po[i]++;
else pi[i]++;
}
cin>>q;
for (int i=1;i<=n;i++) cin>>b[i];
build(1,1,n);
if (seg[1]==n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
while (q--){
int l,r;char x;cin>>l>>r>>x;
edit(1,1,n,l,r,x);
if (seg[1]==n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
# | 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... |