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>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 23;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
ll mod =1865790559;
ll base =937;
ll pw[N];
ll J[N],O[N],I[N];
void meow() {
pw[0] = 1;
for(int i=1;i<N ; i++) {
pw[i] = (pw[i-1] * base) %mod;
J[i] = ('J' + J[i-1]*base) %mod;
O[i] = ('O' + O[i-1]*base) %mod;
I[i] = ('I' + I[i-1]*base) %mod;
}
}
int n,q;
string beg;
string a,b,c;
vector<string> strs;
vector<ll> hshs;
ll t[N<<2];
char lz[N<<2];
void build(int v=1,int tl=1,int tr = n+1) {
lz[v] = '-';
if(tr-tl == 1) {
t[v] = beg[tl];
return;
}
int mid=(tl+tr)/2;
build(lc,tl,mid);
build(rc,mid,tr);
t[v] = (t[lc] + t[rc] * pw[mid-tl]) %mod;
}
void shift(int v,int tl,int mid,int tr) {
if(lz[v] == '-') return;
if(lz[v] == 'J') {
t[lc] = J[mid-tl];
t[rc] = J[tr-mid];
}
if(lz[v] == 'O') {
t[lc] = O[mid-tl];
t[rc] = O[tr-mid];
}
if(lz[v] == 'I') {
t[lc] = I[mid-tl];
t[rc] = I[tr-mid];
}
lz[lc] = lz[rc] = lz[v];
lz[v] = '-';
}
void upd(int l,int r,char c,int v=1,int tl = 1,int tr= n+1) {
if(l > r) return;
if(l == tl && r == tr-1) {
if(c == 'J') t[v] = J[tr-tl];
if(c == 'O') t[v] = O[tr-tl];
if(c == 'I') t[v] = I[tr-tl];
lz[v]= c;
return;
}
int mid=(tl+tr)/2;
shift(v,tl,mid,tr);
upd(l,min(mid-1,r),c,lc,tl,mid);
upd(max(l,mid),r,c,rc,mid,tr);
t[v] = (t[lc] + t[rc] * pw[mid-tl]) %mod;
}
ll getHash(string s) {
ll hash = 0;
reverse(all(s));
for(char c : s) {
if(c == '#') continue;
hash = (c + hash*base) %mod;
}
return hash;
}
string cross(string one,string two) {
string ans; ans.resize(n+1);
for(int i = 0; i <= n ; i++) {
if(one[i] == two[i]) ans[i] = one[i];
else{
if('J' != one[i] && 'J' != two[i]) ans[i] = 'J';
else if('O' != one[i] && 'O' != two[i]) ans[i] = 'O';
else ans[i] = 'I';
}
}
return ans;
}
void out() {
bool ans = 0;
for(ll hsh : hshs) {
debug(t[1] ,hsh);
ans |= (t[1] == hsh);
}
cout<<(ans ? "Yes" : "No") << '\n';
}
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
meow();
cin>>n>>a>>b>>c; a= "#" + a; b = "#" + b; c = "#" + c;
strs.pb(a);
strs.pb(b);
strs.pb(c);
strs.pb(cross(a,b));
strs.pb(cross(a,c));
strs.pb(cross(b,c));
strs.pb(cross(cross(a,b),c));
strs.pb(cross(cross(a,c),b));
strs.pb(cross(cross(b,a),c));
strs.pb(cross(cross(b,c),a));
strs.pb(cross(cross(c,a),b));
strs.pb(cross(cross(c,b),a));
for(string s : strs) hshs.pb(getHash(s));
cin>>q;
cin>>beg; beg = "#" + beg;
build();
debug(t[1]);
out();
while(q--) {
int l,r; char c; cin>>l>>r>>c;
upd(l,r,c);
out();
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void out()':
Main.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
Main.cpp:122:3: note: in expansion of macro 'debug'
122 | debug(t[1] ,hsh);
| ^~~~~
Main.cpp: In function 'int32_t main()':
Main.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
Main.cpp:148:2: note: in expansion of macro 'debug'
148 | debug(t[1]);
| ^~~~~
# | 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... |