#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e5+5, mod=1e9+9;
ll n, mp[100], q, k[10], l, r;
char ch;
vector<ll> qs[3], d[10], p(nx);
string s[3], t;
struct segtree
{
ll d[4*nx], lz[4*nx];
void build(int l, int r, int i)
{
lz[i]=-1;
if (l==r) return void(d[i]=(mp[(int)t[l-1]]*p[l])%mod);
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 pushlz(int l, int r, int i)
{
if (lz[i]==-1) return;
if (l==r) return d[i]=((qs[lz[i]][r]-qs[lz[i]][l-1])%mod+mod)%mod, lz[i]=-1, void();
d[i]=((qs[lz[i]][r]-qs[lz[i]][l-1])%mod+mod)%mod;
lz[2*i]=lz[i];
lz[2*i+1]=lz[i];
lz[i]=-1;
}
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()
{
pushlz(1, n, 1);
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;
}
void show(vector<ll> &x)
{
for (int i=1; i<=n; i++) cout<<x[i];
cout<<'\n';
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
for (int i=0; i<3; i++) qs[i].resize(nx), d[i].resize(nx);
mp['J']=0; mp['O']=1; mp['I']=2;
p[1]=1;
for (int i=2; i<nx; i++) p[i]=(p[i-1]*3)%mod;
for (int i=0; i<3; i++) for (int j=1; j<nx; j++) qs[i][j]=(qs[i][j-1]+i*p[j])%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]);
//for (int i=3; i<9; i++) show(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<<(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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
23380 KB |
Output is correct |
2 |
Correct |
101 ms |
23444 KB |
Output is correct |
3 |
Correct |
78 ms |
23468 KB |
Output is correct |
4 |
Correct |
71 ms |
23376 KB |
Output is correct |
5 |
Correct |
68 ms |
23380 KB |
Output is correct |
6 |
Correct |
70 ms |
23428 KB |
Output is correct |
7 |
Correct |
90 ms |
23668 KB |
Output is correct |
8 |
Correct |
69 ms |
23380 KB |
Output is correct |
9 |
Correct |
91 ms |
23456 KB |
Output is correct |
10 |
Incorrect |
72 ms |
23380 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
23380 KB |
Output is correct |
2 |
Correct |
101 ms |
23444 KB |
Output is correct |
3 |
Correct |
78 ms |
23468 KB |
Output is correct |
4 |
Correct |
71 ms |
23376 KB |
Output is correct |
5 |
Correct |
68 ms |
23380 KB |
Output is correct |
6 |
Correct |
70 ms |
23428 KB |
Output is correct |
7 |
Correct |
90 ms |
23668 KB |
Output is correct |
8 |
Correct |
69 ms |
23380 KB |
Output is correct |
9 |
Correct |
91 ms |
23456 KB |
Output is correct |
10 |
Incorrect |
72 ms |
23380 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
23380 KB |
Output is correct |
2 |
Correct |
101 ms |
23444 KB |
Output is correct |
3 |
Correct |
78 ms |
23468 KB |
Output is correct |
4 |
Correct |
71 ms |
23376 KB |
Output is correct |
5 |
Correct |
68 ms |
23380 KB |
Output is correct |
6 |
Correct |
70 ms |
23428 KB |
Output is correct |
7 |
Correct |
90 ms |
23668 KB |
Output is correct |
8 |
Correct |
69 ms |
23380 KB |
Output is correct |
9 |
Correct |
91 ms |
23456 KB |
Output is correct |
10 |
Incorrect |
72 ms |
23380 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
23380 KB |
Output is correct |
2 |
Correct |
101 ms |
23444 KB |
Output is correct |
3 |
Correct |
78 ms |
23468 KB |
Output is correct |
4 |
Correct |
71 ms |
23376 KB |
Output is correct |
5 |
Correct |
68 ms |
23380 KB |
Output is correct |
6 |
Correct |
70 ms |
23428 KB |
Output is correct |
7 |
Correct |
90 ms |
23668 KB |
Output is correct |
8 |
Correct |
69 ms |
23380 KB |
Output is correct |
9 |
Correct |
91 ms |
23456 KB |
Output is correct |
10 |
Incorrect |
72 ms |
23380 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |