#include<bits/stdc++.h>
#define fs first
#define sc second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const ll mod=1e9+3,N=200005;
ll n,q,h[10],t[N<<2],lz[N<<2],p[N],pre[N];
string s[10],cur;
char c[5]={'J','O','I'};
string xr(string a,string b)
{
string res="";
for(int i=0;i<n;i++)
{
if(a[i]==b[i])
{
res+=a[i];
continue;
}
for(int j=0;j<3;j++)
if(c[j]!=a[i] and c[j]!=b[i])
{
res+=c[j];
break;
}
}
return res;
}
void process()
{
pre[0]=p[0]=1;
for(int i=1;i<=n;i++)
{
p[i]=(p[i-1]*31)%mod;
pre[i]=(pre[i-1]+p[i])%mod;
}
for(int pos=1;pos<=9;pos++)
for(int i=0;i<n;i++)
h[pos]=(h[pos]+(s[pos][i]-'A')*p[i])%mod;
}
void down(int node,int l,int r)
{
if(!lz[node]) return;
t[node]=(pre[r-l]*lz[node])%mod;
if(l!=r)
{
lz[node<<1]=lz[node];
lz[node<<1|1]=lz[node];
}
lz[node]=0;
}
void upd(int u,int v,int val,int node=1,int l=1,int r=n)
{
down(node,l,r);
if(u>r or v<l or l>r) return;
if(u<=l and r<=v)
{
lz[node]=val;
down(node,l,r);
return;
}
int mid=(l+r)>>1;
upd(u,v,val,node<<1,l,mid);
upd(u,v,val,node<<1|1,mid+1,r);
t[node]=(t[node<<1]+t[node<<1|1]*p[mid-l+1])%mod;
}
ll get()
{
down(1,1,n);
return t[1];
}
bool avail()
{
ll val=get();
for(int pos=1;pos<=9;pos++)
if(val==h[pos])
return 1;
return 0;
}
void solve()
{
cin>>n>>s[1]>>s[2]>>s[3];
s[4]=xr(s[1],s[2]);
s[5]=xr(s[1],s[3]);
s[6]=xr(s[2],s[3]);
s[7]=xr(s[3],s[4]);
s[8]=xr(s[2],s[5]);
s[9]=xr(s[1],s[6]);
process();
cin>>q>>cur;
cur=' '+cur;
for(int i=1;i<=n;i++)
upd(i,i,cur[i]-'A');
if(avail())
cout<<"Yes\n";
else
cout<<"No\n";
while(q--)
{
int l,r; char c;
cin>>l>>r>>c;
upd(l,r,c-'A');
if(avail())
cout<<"Yes\n";
else
cout<<"No\n";
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define TASK "a"
#ifndef EVAL
freopen(TASK".inp","r",stdin);
freopen(TASK".out","w",stdout);
#endif
int test=1;
// cin>>test;
while(test--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
1272 KB |
Output is correct |
2 |
Correct |
76 ms |
1324 KB |
Output is correct |
3 |
Correct |
88 ms |
1252 KB |
Output is correct |
4 |
Correct |
65 ms |
1264 KB |
Output is correct |
5 |
Correct |
64 ms |
1256 KB |
Output is correct |
6 |
Correct |
65 ms |
1236 KB |
Output is correct |
7 |
Correct |
62 ms |
1232 KB |
Output is correct |
8 |
Correct |
67 ms |
1280 KB |
Output is correct |
9 |
Correct |
66 ms |
1228 KB |
Output is correct |
10 |
Correct |
67 ms |
1268 KB |
Output is correct |
11 |
Correct |
69 ms |
1312 KB |
Output is correct |
12 |
Correct |
67 ms |
1296 KB |
Output is correct |
13 |
Correct |
72 ms |
1264 KB |
Output is correct |
14 |
Correct |
71 ms |
1280 KB |
Output is correct |
15 |
Correct |
91 ms |
1304 KB |
Output is correct |
16 |
Correct |
69 ms |
1272 KB |
Output is correct |
17 |
Correct |
70 ms |
1236 KB |
Output is correct |
18 |
Correct |
75 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
1272 KB |
Output is correct |
2 |
Correct |
76 ms |
1324 KB |
Output is correct |
3 |
Correct |
88 ms |
1252 KB |
Output is correct |
4 |
Correct |
65 ms |
1264 KB |
Output is correct |
5 |
Correct |
64 ms |
1256 KB |
Output is correct |
6 |
Correct |
65 ms |
1236 KB |
Output is correct |
7 |
Correct |
62 ms |
1232 KB |
Output is correct |
8 |
Correct |
67 ms |
1280 KB |
Output is correct |
9 |
Correct |
66 ms |
1228 KB |
Output is correct |
10 |
Correct |
67 ms |
1268 KB |
Output is correct |
11 |
Correct |
69 ms |
1312 KB |
Output is correct |
12 |
Correct |
67 ms |
1296 KB |
Output is correct |
13 |
Correct |
72 ms |
1264 KB |
Output is correct |
14 |
Correct |
71 ms |
1280 KB |
Output is correct |
15 |
Correct |
91 ms |
1304 KB |
Output is correct |
16 |
Correct |
69 ms |
1272 KB |
Output is correct |
17 |
Correct |
70 ms |
1236 KB |
Output is correct |
18 |
Correct |
75 ms |
1228 KB |
Output is correct |
19 |
Correct |
307 ms |
14672 KB |
Output is correct |
20 |
Correct |
376 ms |
13900 KB |
Output is correct |
21 |
Correct |
248 ms |
14476 KB |
Output is correct |
22 |
Correct |
224 ms |
13824 KB |
Output is correct |
23 |
Correct |
116 ms |
2124 KB |
Output is correct |
24 |
Correct |
144 ms |
2048 KB |
Output is correct |
25 |
Correct |
283 ms |
14628 KB |
Output is correct |
26 |
Correct |
220 ms |
14680 KB |
Output is correct |
27 |
Correct |
252 ms |
14752 KB |
Output is correct |
28 |
Correct |
266 ms |
14688 KB |
Output is correct |
29 |
Correct |
228 ms |
14548 KB |
Output is correct |
30 |
Correct |
135 ms |
2140 KB |
Output is correct |
31 |
Correct |
244 ms |
14700 KB |
Output is correct |
32 |
Correct |
244 ms |
14136 KB |
Output is correct |
33 |
Correct |
112 ms |
2124 KB |
Output is correct |
34 |
Correct |
238 ms |
14740 KB |
Output is correct |
35 |
Correct |
227 ms |
13248 KB |
Output is correct |
36 |
Correct |
112 ms |
2116 KB |
Output is correct |
37 |
Correct |
111 ms |
2204 KB |
Output is correct |
38 |
Correct |
245 ms |
13912 KB |
Output is correct |
39 |
Correct |
187 ms |
13652 KB |
Output is correct |
40 |
Correct |
223 ms |
9032 KB |
Output is correct |
41 |
Correct |
282 ms |
14904 KB |
Output is correct |
42 |
Correct |
120 ms |
13844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
1272 KB |
Output is correct |
2 |
Correct |
76 ms |
1324 KB |
Output is correct |
3 |
Correct |
88 ms |
1252 KB |
Output is correct |
4 |
Correct |
65 ms |
1264 KB |
Output is correct |
5 |
Correct |
64 ms |
1256 KB |
Output is correct |
6 |
Correct |
65 ms |
1236 KB |
Output is correct |
7 |
Correct |
62 ms |
1232 KB |
Output is correct |
8 |
Correct |
67 ms |
1280 KB |
Output is correct |
9 |
Correct |
66 ms |
1228 KB |
Output is correct |
10 |
Correct |
67 ms |
1268 KB |
Output is correct |
11 |
Correct |
69 ms |
1312 KB |
Output is correct |
12 |
Correct |
67 ms |
1296 KB |
Output is correct |
13 |
Correct |
72 ms |
1264 KB |
Output is correct |
14 |
Correct |
71 ms |
1280 KB |
Output is correct |
15 |
Correct |
91 ms |
1304 KB |
Output is correct |
16 |
Correct |
69 ms |
1272 KB |
Output is correct |
17 |
Correct |
70 ms |
1236 KB |
Output is correct |
18 |
Correct |
75 ms |
1228 KB |
Output is correct |
19 |
Correct |
72 ms |
1264 KB |
Output is correct |
20 |
Correct |
74 ms |
1248 KB |
Output is correct |
21 |
Correct |
77 ms |
1280 KB |
Output is correct |
22 |
Correct |
63 ms |
1184 KB |
Output is correct |
23 |
Correct |
69 ms |
1312 KB |
Output is correct |
24 |
Correct |
65 ms |
1196 KB |
Output is correct |
25 |
Correct |
69 ms |
1260 KB |
Output is correct |
26 |
Correct |
62 ms |
1188 KB |
Output is correct |
27 |
Correct |
73 ms |
1264 KB |
Output is correct |
28 |
Correct |
74 ms |
1268 KB |
Output is correct |
29 |
Correct |
76 ms |
1224 KB |
Output is correct |
30 |
Correct |
56 ms |
1168 KB |
Output is correct |
31 |
Correct |
63 ms |
1228 KB |
Output is correct |
32 |
Correct |
66 ms |
1332 KB |
Output is correct |
33 |
Correct |
73 ms |
1296 KB |
Output is correct |
34 |
Correct |
76 ms |
1188 KB |
Output is correct |
35 |
Correct |
68 ms |
1220 KB |
Output is correct |
36 |
Correct |
65 ms |
1324 KB |
Output is correct |
37 |
Correct |
91 ms |
1228 KB |
Output is correct |
38 |
Correct |
64 ms |
1396 KB |
Output is correct |
39 |
Correct |
64 ms |
1292 KB |
Output is correct |
40 |
Correct |
63 ms |
1228 KB |
Output is correct |
41 |
Correct |
69 ms |
1228 KB |
Output is correct |
42 |
Correct |
64 ms |
1284 KB |
Output is correct |
43 |
Correct |
61 ms |
1228 KB |
Output is correct |
44 |
Correct |
85 ms |
1208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
1272 KB |
Output is correct |
2 |
Correct |
76 ms |
1324 KB |
Output is correct |
3 |
Correct |
88 ms |
1252 KB |
Output is correct |
4 |
Correct |
65 ms |
1264 KB |
Output is correct |
5 |
Correct |
64 ms |
1256 KB |
Output is correct |
6 |
Correct |
65 ms |
1236 KB |
Output is correct |
7 |
Correct |
62 ms |
1232 KB |
Output is correct |
8 |
Correct |
67 ms |
1280 KB |
Output is correct |
9 |
Correct |
66 ms |
1228 KB |
Output is correct |
10 |
Correct |
67 ms |
1268 KB |
Output is correct |
11 |
Correct |
69 ms |
1312 KB |
Output is correct |
12 |
Correct |
67 ms |
1296 KB |
Output is correct |
13 |
Correct |
72 ms |
1264 KB |
Output is correct |
14 |
Correct |
71 ms |
1280 KB |
Output is correct |
15 |
Correct |
91 ms |
1304 KB |
Output is correct |
16 |
Correct |
69 ms |
1272 KB |
Output is correct |
17 |
Correct |
70 ms |
1236 KB |
Output is correct |
18 |
Correct |
75 ms |
1228 KB |
Output is correct |
19 |
Correct |
307 ms |
14672 KB |
Output is correct |
20 |
Correct |
376 ms |
13900 KB |
Output is correct |
21 |
Correct |
248 ms |
14476 KB |
Output is correct |
22 |
Correct |
224 ms |
13824 KB |
Output is correct |
23 |
Correct |
116 ms |
2124 KB |
Output is correct |
24 |
Correct |
144 ms |
2048 KB |
Output is correct |
25 |
Correct |
283 ms |
14628 KB |
Output is correct |
26 |
Correct |
220 ms |
14680 KB |
Output is correct |
27 |
Correct |
252 ms |
14752 KB |
Output is correct |
28 |
Correct |
266 ms |
14688 KB |
Output is correct |
29 |
Correct |
228 ms |
14548 KB |
Output is correct |
30 |
Correct |
135 ms |
2140 KB |
Output is correct |
31 |
Correct |
244 ms |
14700 KB |
Output is correct |
32 |
Correct |
244 ms |
14136 KB |
Output is correct |
33 |
Correct |
112 ms |
2124 KB |
Output is correct |
34 |
Correct |
238 ms |
14740 KB |
Output is correct |
35 |
Correct |
227 ms |
13248 KB |
Output is correct |
36 |
Correct |
112 ms |
2116 KB |
Output is correct |
37 |
Correct |
111 ms |
2204 KB |
Output is correct |
38 |
Correct |
245 ms |
13912 KB |
Output is correct |
39 |
Correct |
187 ms |
13652 KB |
Output is correct |
40 |
Correct |
223 ms |
9032 KB |
Output is correct |
41 |
Correct |
282 ms |
14904 KB |
Output is correct |
42 |
Correct |
120 ms |
13844 KB |
Output is correct |
43 |
Correct |
72 ms |
1264 KB |
Output is correct |
44 |
Correct |
74 ms |
1248 KB |
Output is correct |
45 |
Correct |
77 ms |
1280 KB |
Output is correct |
46 |
Correct |
63 ms |
1184 KB |
Output is correct |
47 |
Correct |
69 ms |
1312 KB |
Output is correct |
48 |
Correct |
65 ms |
1196 KB |
Output is correct |
49 |
Correct |
69 ms |
1260 KB |
Output is correct |
50 |
Correct |
62 ms |
1188 KB |
Output is correct |
51 |
Correct |
73 ms |
1264 KB |
Output is correct |
52 |
Correct |
74 ms |
1268 KB |
Output is correct |
53 |
Correct |
76 ms |
1224 KB |
Output is correct |
54 |
Correct |
56 ms |
1168 KB |
Output is correct |
55 |
Correct |
63 ms |
1228 KB |
Output is correct |
56 |
Correct |
66 ms |
1332 KB |
Output is correct |
57 |
Correct |
73 ms |
1296 KB |
Output is correct |
58 |
Correct |
76 ms |
1188 KB |
Output is correct |
59 |
Correct |
68 ms |
1220 KB |
Output is correct |
60 |
Correct |
65 ms |
1324 KB |
Output is correct |
61 |
Correct |
91 ms |
1228 KB |
Output is correct |
62 |
Correct |
64 ms |
1396 KB |
Output is correct |
63 |
Correct |
64 ms |
1292 KB |
Output is correct |
64 |
Correct |
63 ms |
1228 KB |
Output is correct |
65 |
Correct |
69 ms |
1228 KB |
Output is correct |
66 |
Correct |
64 ms |
1284 KB |
Output is correct |
67 |
Correct |
61 ms |
1228 KB |
Output is correct |
68 |
Correct |
85 ms |
1208 KB |
Output is correct |
69 |
Correct |
247 ms |
13620 KB |
Output is correct |
70 |
Correct |
310 ms |
13876 KB |
Output is correct |
71 |
Correct |
120 ms |
2064 KB |
Output is correct |
72 |
Correct |
104 ms |
2084 KB |
Output is correct |
73 |
Correct |
102 ms |
2056 KB |
Output is correct |
74 |
Correct |
236 ms |
14028 KB |
Output is correct |
75 |
Correct |
105 ms |
2044 KB |
Output is correct |
76 |
Correct |
223 ms |
14696 KB |
Output is correct |
77 |
Correct |
229 ms |
13732 KB |
Output is correct |
78 |
Correct |
99 ms |
2124 KB |
Output is correct |
79 |
Correct |
106 ms |
2224 KB |
Output is correct |
80 |
Correct |
208 ms |
13000 KB |
Output is correct |
81 |
Correct |
108 ms |
2096 KB |
Output is correct |
82 |
Correct |
226 ms |
14724 KB |
Output is correct |
83 |
Correct |
240 ms |
14336 KB |
Output is correct |
84 |
Correct |
104 ms |
2052 KB |
Output is correct |
85 |
Correct |
99 ms |
2064 KB |
Output is correct |
86 |
Correct |
242 ms |
13400 KB |
Output is correct |
87 |
Correct |
244 ms |
14676 KB |
Output is correct |
88 |
Correct |
107 ms |
2120 KB |
Output is correct |
89 |
Correct |
225 ms |
13904 KB |
Output is correct |
90 |
Correct |
246 ms |
14936 KB |
Output is correct |
91 |
Correct |
110 ms |
2088 KB |
Output is correct |
92 |
Correct |
229 ms |
13224 KB |
Output is correct |
93 |
Correct |
115 ms |
2132 KB |
Output is correct |
94 |
Correct |
103 ms |
2132 KB |
Output is correct |
95 |
Correct |
108 ms |
2112 KB |
Output is correct |
96 |
Correct |
240 ms |
13948 KB |
Output is correct |
97 |
Correct |
192 ms |
13624 KB |
Output is correct |
98 |
Correct |
223 ms |
9028 KB |
Output is correct |
99 |
Correct |
318 ms |
14932 KB |
Output is correct |
100 |
Correct |
125 ms |
13864 KB |
Output is correct |