#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e5+5, mod=1e9+7;
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 build(ll l, ll r, ll i)
{
lz[i]=-1;
if (l==r) return void(d[i]=(mp[(ll)t[l-1]]*p[l])%mod);
ll 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 pushlz(ll l, ll r, ll 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 update(ll l, ll r, ll i, ll ql, ll qr, ll 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();
ll 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 (ll i=0; i<9; i++) if (k[i]==d[1]) return 1;
return 0;
}
} st;
ll getval(vector<ll> &str)
{
ll res=0;
for (ll 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 (ll 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 (ll i=0; i<9; i++) d[i].resize(nx);
mp['J']=0; mp['O']=1; mp['I']=2;
p[1]=qsp[1]=1;
for (ll i=2; i<nx; i++) p[i]=(p[i-1]*3)%mod, qsp[i]=(qsp[i-1]+p[i])%mod;
cin>>n>>s[0]>>s[1]>>s[2];
for (ll i=0; i<3; i++) for (ll j=1; j<=n; j++) d[i][j]=mp[(ll)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 (ll 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[(ll)ch]);
//cout<<"here "<<st.d[1]<<'\n';
cout<<(st.check()?"Yes":"No")<<'\n';
}
}
/*
3
JOI
JOI
JOI
5
JOI
1 3 O
1 3 I
1 2 J
2 2 O
3 3 I
20
OOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOOOO
5
OOOOOOOOOOOOOOOOOOOO
1 2 J
1 2 O
1 2 I
1 2 O
1 2 O
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
20124 KB |
Output is correct |
2 |
Correct |
73 ms |
20144 KB |
Output is correct |
3 |
Correct |
70 ms |
20136 KB |
Output is correct |
4 |
Correct |
61 ms |
20144 KB |
Output is correct |
5 |
Correct |
71 ms |
20168 KB |
Output is correct |
6 |
Correct |
75 ms |
20344 KB |
Output is correct |
7 |
Correct |
62 ms |
20120 KB |
Output is correct |
8 |
Correct |
65 ms |
20464 KB |
Output is correct |
9 |
Correct |
66 ms |
20332 KB |
Output is correct |
10 |
Incorrect |
68 ms |
20132 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
20124 KB |
Output is correct |
2 |
Correct |
73 ms |
20144 KB |
Output is correct |
3 |
Correct |
70 ms |
20136 KB |
Output is correct |
4 |
Correct |
61 ms |
20144 KB |
Output is correct |
5 |
Correct |
71 ms |
20168 KB |
Output is correct |
6 |
Correct |
75 ms |
20344 KB |
Output is correct |
7 |
Correct |
62 ms |
20120 KB |
Output is correct |
8 |
Correct |
65 ms |
20464 KB |
Output is correct |
9 |
Correct |
66 ms |
20332 KB |
Output is correct |
10 |
Incorrect |
68 ms |
20132 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
20124 KB |
Output is correct |
2 |
Correct |
73 ms |
20144 KB |
Output is correct |
3 |
Correct |
70 ms |
20136 KB |
Output is correct |
4 |
Correct |
61 ms |
20144 KB |
Output is correct |
5 |
Correct |
71 ms |
20168 KB |
Output is correct |
6 |
Correct |
75 ms |
20344 KB |
Output is correct |
7 |
Correct |
62 ms |
20120 KB |
Output is correct |
8 |
Correct |
65 ms |
20464 KB |
Output is correct |
9 |
Correct |
66 ms |
20332 KB |
Output is correct |
10 |
Incorrect |
68 ms |
20132 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
20124 KB |
Output is correct |
2 |
Correct |
73 ms |
20144 KB |
Output is correct |
3 |
Correct |
70 ms |
20136 KB |
Output is correct |
4 |
Correct |
61 ms |
20144 KB |
Output is correct |
5 |
Correct |
71 ms |
20168 KB |
Output is correct |
6 |
Correct |
75 ms |
20344 KB |
Output is correct |
7 |
Correct |
62 ms |
20120 KB |
Output is correct |
8 |
Correct |
65 ms |
20464 KB |
Output is correct |
9 |
Correct |
66 ms |
20332 KB |
Output is correct |
10 |
Incorrect |
68 ms |
20132 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |