Submission #881315

#TimeUsernameProblemLanguageResultExecution timeMemory
881315AlishCrossing (JOI21_crossing)C++17
100 / 100
284 ms26440 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long int	ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;


#define F		        first
#define S		        second
#define pb		        push_back
#define endl            '\n'
#define Mp		        make_pair
#define all(x)          x.begin(), x.end()
#define debug(x)        cerr << #x << " = " << x << endl;
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("connect.in" , "r" , stdin) ; freopen("connect.out" , "w" , stdout);


ll mod = 1000696969;


const int N = 2e5+23;
ll base=737;

ll seg[4*N], lpz[4*N];
string s[3];
ll pw[N];
int n, q;
ll temp[N];
ll temphsh[N];
set<ll> hsh;

string t;

ll blo[3][N];


int get(char c){
    if(c=='I') return 0;
    if(c=='O') return 1;
    return 2;
}



void Shift(int l, int r, int ind){
    if(r-l==1)return;
    if(lpz[ind]==-1) return;
    int mid=(r+l)>>1;

    lpz[2*ind+1]=lpz[ind];
    lpz[2*ind+2]=lpz[ind];

    seg[2*ind+1]=blo[lpz[ind]][mid-l-1];
    seg[2*ind+2]=blo[lpz[ind]][r-mid-1];
    lpz[ind]=-1;

}

void upd(int lx, int rx,  int v, int l=0, int r=n, int ind=0){
    Shift(l, r, ind);
    if(lx>=r || rx<=l) return ;
    if(lx<=l && rx>=r){
        seg[ind]=blo[v][r-l-1];
        lpz[ind]=v;
        return;
    }
    int mid=(r+l)>>1;
    upd(lx, rx, v, l, mid, 2*ind+1); upd(lx, rx, v, mid, r, 2*ind+2);
    seg[ind]=(seg[2*ind+1]+seg[2*ind+2]*pw[mid-l]%mod)%mod;
}

void build(int l=0, int r=n, int ind=0){

    lpz[ind]=-1;
    if(r-l==1){
        seg[ind]=temp[l];
        return;
    }
    int mid=(r+l)>>1;
    build(l, mid, 2*ind+1); build(mid, r, 2*ind+2);
    seg[ind]=(seg[2*ind+1]+seg[2*ind+2]*pw[mid-l]%mod)%mod;


}

void getC(int i, int l=0, int r=n, int ind=0){
    Shift(l, r, ind);
    if(r-l==1){
        cout<<seg[ind];
        return;
    }
    int mid=(r+l)>>1;
    if(i<mid) getC(i, l, mid, 2*ind+1);
    else getC(i, mid, r, 2*ind+2);
}

int main()
{
    fast_io
    pw[0]=1;
    for (int i=1; i<N; i++)pw[i]=pw[i-1]*base%mod;
    for (int k=0; k<3; k++)for (int i=0; i<N; i++){
        blo[k][i]=k*pw[i]%mod;
        if(i) blo[k][i]=(blo[k][i]+blo[k][i-1])%mod;
    }
    cin>>n;
    for (int i=0; i<3; i++) cin>>s[i];

    for(int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            for (int k=0; k<3; k++){

                for (int g=0; g<n; g++){
                    ll a=(3-(3-get(s[i][g])-get(s[j][g])+6)%3-get(s[k][g])+6)%3;
                    temphsh[g]=a*pw[g]%mod;
                    if(g) temphsh[g]=(temphsh[g-1]+temphsh[g])%mod;
                }
                hsh.insert(temphsh[n-1]);
            }
        }
    }

    cin>>q;
    cin>>t;
    for (int i=0; i<n; i++)temp[i]=get(t[i]);

    build();

    if(hsh.find(seg[0])!=hsh.end()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    while(q--){
        int l, r;
        char c;
        cin>>l>>r>>c;
        l--;
        int t=get(c);
        upd(l, r, t);
        if(hsh.find(seg[0])!=hsh.end()) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...