제출 #861191

#제출 시각아이디문제언어결과실행 시간메모리
861191vjudge1Crossing (JOI21_crossing)C++17
0 / 100
506 ms10288 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #define pii pair<int,int> #define F first #define S second #define endl '\n' #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() const int mod = 1e9 + 7; const int N = 1e6 + 15; const ll inf = 1e18; template<class T> bool ckmin(T &a, T b){ return (a > b ? a=b, true : false); } template<class T> bool ckmax(T &a, T b){ return (a < b ? a=b, true : false); } int mul(int a, int b){ return (a*b)%mod; } int add(int a, int b){ int c = (a+b)%mod; if (c<0) c += mod; return c; } int sub(int a, int b){ return add(a, -b); } int pw(int a, int b){ int r = 1; while (b){ if (b&1){ r=mul(a,r); } a = mul(a, a); b >>= 1; } return r; }// !! int inv(int a){ return pw(a, mod-2); } #define ls (idx << 1) #define rs (idx << 1 | 1) const int off = (1<<18); int t[off*2]; int lazy[off*2]; int A[N]; int n; void push(int idx, int lo, int hi){ if (!lazy[idx]) return; lazy[idx] --; int val = lazy[idx]; t[idx] = mul(add(pw(3ll, hi),1ll), inv(sub(3, 1))); t[idx] = sub(t[idx], mul(add(pw(3ll, lo),1ll), inv(sub(3, 1)))); t[idx] = mul(t[idx], val); if (idx < off) { lazy[ls] = lazy[idx]+1; lazy[rs] = lazy[idx]+1; } lazy[idx] = 0; } void update(int l, int r, int val, int idx=1, int lo=0, int hi=off){ push(idx,lo,hi); if (lo>=r||hi<=l) return; if (lo>=l&&hi<=r) { lazy[idx]=val+1; push(idx, lo, hi); return; } int mi = (lo+hi)/2; update(l,r,val,ls,lo,mi); update(l,r,val,rs,mi,hi); t[idx] = (t[ls]+t[rs])%mod; } void build(int idx){ if (idx>=off){ t[idx] = mul(A[idx-off],pw(3ll, idx-off)); return; } build(ls);build(rs); t[idx] = (t[ls]+t[rs])%mod; return; } int hsh(string s){ int p = 1; int r = 0; for (int i=0;i<n;i++){ if (s[i]=='J') r = add(r, p*0); if (s[i]=='O') r = add(r, p*1); if (s[i]=='I') r = add(r, p*2); p = mul(p, 3ll); } return r; } string cross(string a, string b){ string tm; tm.resize(n); for (int i=0;i<n;i++){ if (a[i]==b[i]) tm[i] = a[i]; else { if ('J'!=a[i]&&'J'!=b[i]) tm[i] = 'J'; else if ('O'!=a[i]&&'O'!=b[i]) tm[i] = 'O'; else if ('I'!=a[i]&&'I'!=b[i]) tm[i] = 'I'; } } return tm; } set<int> st; void chk(){ cout << (st.find(t[1])!=st.end() ? "Yes" : "No" ) << endl; } int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin >> n; string a,b,c; cin >> a >> b >> c; st.insert(hsh(a)); st.insert(hsh(b)); st.insert(hsh(c)); st.insert(hsh(cross(a,b))); st.insert(hsh(cross(a,c))); st.insert(hsh(cross(b,c))); st.insert(hsh(cross(a,cross(b,c)))); st.insert(hsh(cross(b,cross(a,c)))); st.insert(hsh(cross(c,cross(a,b)))); int q; cin >> q; string tm; cin >> tm; for (int i=0;i<n;i++){ if (tm[i]=='J')A[i]=0; if (tm[i]=='O')A[i]=1; if (tm[i]=='I')A[i]=2; } build(1); chk(); while (q--){ int l, r; char x; cin >> l >> r >> x; if (x=='J'){ update(l-1, r, 0); } if (x=='O'){ update(l-1, r, 1); } if (x=='I'){ update(l-1, r, 2); } chk(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...