제출 #916175

#제출 시각아이디문제언어결과실행 시간메모리
91617512345678Crossing (JOI21_crossing)C++17
100 / 100
262 ms33516 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long mt19937 rng(time(NULL)); const int nx=2e5+5, mod=1e9+7, base=(rng()%mod+mod)%mod; ll n, mp[100], q, k[10], l, r; char ch; vector<ll> d[10], p(nx), qsp(nx); string s[3], t; struct segtree { ll d[4*nx], lz[4*nx]; void pushlz(int l, int r, int i) { if (lz[i]==-1) return; if (l==r) return d[i]=(((qsp[r]-qsp[l-1])*lz[i])%mod+mod)%mod, lz[i]=-1, void(); d[i]=(((qsp[r]-qsp[l-1])*lz[i])%mod+mod)%mod; lz[2*i]=lz[i]; lz[2*i+1]=lz[i]; lz[i]=-1; } void build(int l, int r, int i) { lz[i]=-1; if (l==r) return lz[i]=mp[(int)t[l-1]], pushlz(l, r, i); int md=(l+r)/2; build(l, md, 2*i); build(md+1, r, 2*i+1); d[i]=(d[2*i]+d[2*i+1])%mod; } void update(int l, int r, int i, int ql, int qr, int vl) { pushlz(l, r, i); if (qr<l||r<ql) return; if (ql<=l&&r<=qr) return lz[i]=vl, pushlz(l, r, i), void(); int md=(l+r)/2; update(l, md, 2*i, ql, qr, vl); update(md+1, r, 2*i+1, ql, qr, vl); d[i]=(d[2*i]+d[2*i+1])%mod; } bool check() { for (int i=0; i<9; i++) if (k[i]==d[1]) return 1; return 0; } } st; ll getval(vector<ll> &str) { ll res=0; for (int i=1; i<=n; i++) res=(res+p[i]*str[i])%mod; return res; } vector<ll> cross(vector<ll> &lhs, vector<ll> &rhs) { vector<ll> res(nx); for (int i=1; i<=n; i++) res[i]=((lhs[i]+rhs[i])*2)%3; return res; } int main() { cin.tie(NULL)->sync_with_stdio(false); for (int i=0; i<9; i++) d[i].resize(nx); mp['J']=0; mp['O']=1; mp['I']=2; p[1]=qsp[1]=1; for (int i=2; i<nx; i++) p[i]=(p[i-1]*base)%mod, qsp[i]=(qsp[i-1]+p[i])%mod; cin>>n>>s[0]>>s[1]>>s[2]; for (int i=0; i<3; i++) for (int j=1; j<=n; j++) d[i][j]=mp[(int)s[i][j-1]]; d[3]=cross(d[0], d[1]); d[4]=cross(d[0], d[2]); d[5]=cross(d[1], d[2]); d[6]=cross(d[3], d[2]); d[7]=cross(d[4], d[1]); d[8]=cross(d[5], d[0]); for (int i=0; i<9; i++) k[i]=getval(d[i]); cin>>q>>t; st.build(1, n, 1); cout<<(st.check()?"Yes":"No")<<'\n'; while (q--) { cin>>l>>r>>ch; st.update(1, n, 1, l, r, mp[(int)ch]); //cout<<"here "<<st.d[1]<<'\n'; cout<<(st.check()?"Yes":"No")<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...