#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,hsh[505],pow_97[200005],mod=1000000007,cnt,seg[800005],x,y,t,qs[200005];
char s[10][200005],op[3]={'J','O','I'},chng[5],str[200005],lz[800005];
map<ll,ll> mp;
void cross(char arr1[],char arr2[],char arr3[])
{
for(int i=1;i<=n;i++)
{
if(arr1[i]==arr2[i])
{
arr3[i]=arr1[i];
}else
{
arr3[i]=op[3-hsh[arr1[i]]-hsh[arr2[i]]];
}
}
}
void build(ll tree,ll st,ll ed)
{
ll md=(st+ed)/2;
if(st==ed)
{
seg[tree]=(pow_97[1]*(ll)str[st])%mod;
//printf("%lld %lld %lld\n",st,ed,seg[tree]);
//printf("%c\n",str[st]);
//printf("%lld\n",pow_97[1]);
return;
}
build(2*tree,st,md);
build(2*tree+1,md+1,ed);
seg[tree]=(seg[2*tree]+(pow_97[md-st+1]*seg[2*tree+1])%mod)%mod;
}
void update(ll tree,ll st,ll ed,ll l,ll r,char val)
{
ll md=(st+ed)/2;
if(st>=l&&ed<=r)lz[tree]=val;
if(lz[tree]!=0)
{
if(st!=ed)
{
lz[2*tree]=lz[tree];
lz[2*tree+1]=lz[tree];
}
seg[tree]=(lz[tree]*qs[ed-st+1])%mod;
lz[tree]=0;
}
if(st>=l&&ed<=r)
{
return;
}
if(st>r||ed<l)return;
update(2*tree,st,md,l,r,val);
update(2*tree+1,md+1,ed,l,r,val);
seg[tree]=(seg[2*tree]+(pow_97[md-st+1]*seg[2*tree+1])%mod)%mod;
}
int main()
{
hsh['J']=0,hsh['O']=1,hsh['I']=2;
scanf("%lld",&n);
for(int i=1;i<=3;i++)scanf("%s",s[i]+1);
cross(s[1],s[2],s[4]);
cross(s[1],s[3],s[5]);
cross(s[2],s[3],s[6]);
cross(s[3],s[4],s[7]);
cross(s[2],s[5],s[8]);
cross(s[1],s[6],s[9]);
pow_97[0]=1;
for(int i=1;i<=200000;i++)
{
pow_97[i]=pow_97[i-1]*97;
pow_97[i]%=mod;
}
qs[1]=pow_97[1];
for(int i=2;i<=200000;i++)
{
qs[i]=qs[i-1]+pow_97[i];
qs[i]%=mod;
}
for(int i=1;i<=9;i++)
{
//printf("%d string=%s\n",i,s[i]+1);
cnt=0;
for(int j=1;j<=n;j++)
{
cnt+=(pow_97[j]*s[i][j])%mod;
cnt%=mod;
//printf("%lld ",cnt);
}
//printf("\n");
//printf("%lld\n",cnt);
++mp[cnt];
}
//printf("\n");
scanf("%lld",&t);
scanf("%s",str+1);
build(1,1,n);
//printf("%lld\n",seg[1]);
if(mp[seg[1]]==0)
{
printf("No\n");
}else
{
printf("Yes\n");
}
while(t--)
{
scanf("%lld%lld%s",&x,&y,chng);
//printf("vijak\n");
if(lz[1]!=0)
{
lz[2]=lz[3]=lz[1];
seg[1]=(qs[n]*lz[1])%mod;
lz[1]=0;
}
update(1,1,n,x,y,chng[0]);
if(mp[seg[1]]==0)
{
printf("No\n");
}else
{
printf("Yes\n");
}
}
}
Compilation message
Main.cpp: In function 'void cross(char*, char*, char*)':
Main.cpp:16:36: warning: array subscript has type 'char' [-Wchar-subscripts]
16 | arr3[i]=op[3-hsh[arr1[i]]-hsh[arr2[i]]];
| ~~~~~~^
Main.cpp:16:49: warning: array subscript has type 'char' [-Wchar-subscripts]
16 | arr3[i]=op[3-hsh[arr1[i]]-hsh[arr2[i]]];
| ~~~~~~^
Main.cpp: In function 'int main()':
Main.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
Main.cpp:62:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | for(int i=1;i<=3;i++)scanf("%s",s[i]+1);
| ~~~~~^~~~~~~~~~~~~
Main.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | scanf("%lld",&t);
| ~~~~~^~~~~~~~~~~
Main.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%s",str+1);
| ~~~~~^~~~~~~~~~~~
Main.cpp:109:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | scanf("%lld%lld%s",&x,&y,chng);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
14724 KB |
Output is correct |
2 |
Correct |
184 ms |
15688 KB |
Output is correct |
3 |
Correct |
142 ms |
9148 KB |
Output is correct |
4 |
Correct |
189 ms |
15808 KB |
Output is correct |
5 |
Correct |
200 ms |
15836 KB |
Output is correct |
6 |
Correct |
169 ms |
14972 KB |
Output is correct |
7 |
Correct |
169 ms |
15212 KB |
Output is correct |
8 |
Correct |
190 ms |
16004 KB |
Output is correct |
9 |
Correct |
186 ms |
15620 KB |
Output is correct |
10 |
Correct |
190 ms |
17076 KB |
Output is correct |
11 |
Correct |
192 ms |
16348 KB |
Output is correct |
12 |
Correct |
197 ms |
17212 KB |
Output is correct |
13 |
Correct |
185 ms |
16416 KB |
Output is correct |
14 |
Correct |
207 ms |
17208 KB |
Output is correct |
15 |
Correct |
195 ms |
16324 KB |
Output is correct |
16 |
Correct |
181 ms |
17100 KB |
Output is correct |
17 |
Correct |
189 ms |
16312 KB |
Output is correct |
18 |
Correct |
122 ms |
7472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
14724 KB |
Output is correct |
2 |
Correct |
184 ms |
15688 KB |
Output is correct |
3 |
Correct |
142 ms |
9148 KB |
Output is correct |
4 |
Correct |
189 ms |
15808 KB |
Output is correct |
5 |
Correct |
200 ms |
15836 KB |
Output is correct |
6 |
Correct |
169 ms |
14972 KB |
Output is correct |
7 |
Correct |
169 ms |
15212 KB |
Output is correct |
8 |
Correct |
190 ms |
16004 KB |
Output is correct |
9 |
Correct |
186 ms |
15620 KB |
Output is correct |
10 |
Correct |
190 ms |
17076 KB |
Output is correct |
11 |
Correct |
192 ms |
16348 KB |
Output is correct |
12 |
Correct |
197 ms |
17212 KB |
Output is correct |
13 |
Correct |
185 ms |
16416 KB |
Output is correct |
14 |
Correct |
207 ms |
17208 KB |
Output is correct |
15 |
Correct |
195 ms |
16324 KB |
Output is correct |
16 |
Correct |
181 ms |
17100 KB |
Output is correct |
17 |
Correct |
189 ms |
16312 KB |
Output is correct |
18 |
Correct |
122 ms |
7472 KB |
Output is correct |
19 |
Correct |
421 ms |
23968 KB |
Output is correct |
20 |
Correct |
388 ms |
24268 KB |
Output is correct |
21 |
Correct |
337 ms |
25300 KB |
Output is correct |
22 |
Correct |
300 ms |
22984 KB |
Output is correct |
23 |
Correct |
254 ms |
19368 KB |
Output is correct |
24 |
Correct |
263 ms |
18032 KB |
Output is correct |
25 |
Correct |
343 ms |
26304 KB |
Output is correct |
26 |
Correct |
323 ms |
24416 KB |
Output is correct |
27 |
Correct |
360 ms |
26956 KB |
Output is correct |
28 |
Correct |
366 ms |
24396 KB |
Output is correct |
29 |
Correct |
360 ms |
26364 KB |
Output is correct |
30 |
Correct |
261 ms |
19252 KB |
Output is correct |
31 |
Correct |
361 ms |
26716 KB |
Output is correct |
32 |
Correct |
345 ms |
23996 KB |
Output is correct |
33 |
Correct |
250 ms |
17964 KB |
Output is correct |
34 |
Correct |
339 ms |
24464 KB |
Output is correct |
35 |
Correct |
285 ms |
23756 KB |
Output is correct |
36 |
Correct |
248 ms |
18156 KB |
Output is correct |
37 |
Correct |
262 ms |
18040 KB |
Output is correct |
38 |
Correct |
330 ms |
21452 KB |
Output is correct |
39 |
Correct |
244 ms |
20172 KB |
Output is correct |
40 |
Correct |
308 ms |
21492 KB |
Output is correct |
41 |
Correct |
291 ms |
14540 KB |
Output is correct |
42 |
Correct |
87 ms |
13200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
14724 KB |
Output is correct |
2 |
Correct |
184 ms |
15688 KB |
Output is correct |
3 |
Correct |
142 ms |
9148 KB |
Output is correct |
4 |
Correct |
189 ms |
15808 KB |
Output is correct |
5 |
Correct |
200 ms |
15836 KB |
Output is correct |
6 |
Correct |
169 ms |
14972 KB |
Output is correct |
7 |
Correct |
169 ms |
15212 KB |
Output is correct |
8 |
Correct |
190 ms |
16004 KB |
Output is correct |
9 |
Correct |
186 ms |
15620 KB |
Output is correct |
10 |
Correct |
190 ms |
17076 KB |
Output is correct |
11 |
Correct |
192 ms |
16348 KB |
Output is correct |
12 |
Correct |
197 ms |
17212 KB |
Output is correct |
13 |
Correct |
185 ms |
16416 KB |
Output is correct |
14 |
Correct |
207 ms |
17208 KB |
Output is correct |
15 |
Correct |
195 ms |
16324 KB |
Output is correct |
16 |
Correct |
181 ms |
17100 KB |
Output is correct |
17 |
Correct |
189 ms |
16312 KB |
Output is correct |
18 |
Correct |
122 ms |
7472 KB |
Output is correct |
19 |
Correct |
190 ms |
15188 KB |
Output is correct |
20 |
Correct |
146 ms |
9312 KB |
Output is correct |
21 |
Correct |
187 ms |
16588 KB |
Output is correct |
22 |
Correct |
160 ms |
14548 KB |
Output is correct |
23 |
Correct |
194 ms |
16600 KB |
Output is correct |
24 |
Correct |
182 ms |
15380 KB |
Output is correct |
25 |
Correct |
198 ms |
16580 KB |
Output is correct |
26 |
Correct |
171 ms |
15160 KB |
Output is correct |
27 |
Correct |
189 ms |
16584 KB |
Output is correct |
28 |
Correct |
172 ms |
15332 KB |
Output is correct |
29 |
Correct |
188 ms |
15952 KB |
Output is correct |
30 |
Correct |
160 ms |
14768 KB |
Output is correct |
31 |
Correct |
196 ms |
16760 KB |
Output is correct |
32 |
Correct |
194 ms |
16576 KB |
Output is correct |
33 |
Correct |
185 ms |
16084 KB |
Output is correct |
34 |
Correct |
176 ms |
15212 KB |
Output is correct |
35 |
Correct |
198 ms |
17148 KB |
Output is correct |
36 |
Correct |
187 ms |
16420 KB |
Output is correct |
37 |
Correct |
208 ms |
17140 KB |
Output is correct |
38 |
Correct |
183 ms |
16588 KB |
Output is correct |
39 |
Correct |
195 ms |
17172 KB |
Output is correct |
40 |
Correct |
190 ms |
16304 KB |
Output is correct |
41 |
Correct |
204 ms |
17216 KB |
Output is correct |
42 |
Correct |
191 ms |
16340 KB |
Output is correct |
43 |
Correct |
177 ms |
15708 KB |
Output is correct |
44 |
Correct |
187 ms |
16092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
14724 KB |
Output is correct |
2 |
Correct |
184 ms |
15688 KB |
Output is correct |
3 |
Correct |
142 ms |
9148 KB |
Output is correct |
4 |
Correct |
189 ms |
15808 KB |
Output is correct |
5 |
Correct |
200 ms |
15836 KB |
Output is correct |
6 |
Correct |
169 ms |
14972 KB |
Output is correct |
7 |
Correct |
169 ms |
15212 KB |
Output is correct |
8 |
Correct |
190 ms |
16004 KB |
Output is correct |
9 |
Correct |
186 ms |
15620 KB |
Output is correct |
10 |
Correct |
190 ms |
17076 KB |
Output is correct |
11 |
Correct |
192 ms |
16348 KB |
Output is correct |
12 |
Correct |
197 ms |
17212 KB |
Output is correct |
13 |
Correct |
185 ms |
16416 KB |
Output is correct |
14 |
Correct |
207 ms |
17208 KB |
Output is correct |
15 |
Correct |
195 ms |
16324 KB |
Output is correct |
16 |
Correct |
181 ms |
17100 KB |
Output is correct |
17 |
Correct |
189 ms |
16312 KB |
Output is correct |
18 |
Correct |
122 ms |
7472 KB |
Output is correct |
19 |
Correct |
421 ms |
23968 KB |
Output is correct |
20 |
Correct |
388 ms |
24268 KB |
Output is correct |
21 |
Correct |
337 ms |
25300 KB |
Output is correct |
22 |
Correct |
300 ms |
22984 KB |
Output is correct |
23 |
Correct |
254 ms |
19368 KB |
Output is correct |
24 |
Correct |
263 ms |
18032 KB |
Output is correct |
25 |
Correct |
343 ms |
26304 KB |
Output is correct |
26 |
Correct |
323 ms |
24416 KB |
Output is correct |
27 |
Correct |
360 ms |
26956 KB |
Output is correct |
28 |
Correct |
366 ms |
24396 KB |
Output is correct |
29 |
Correct |
360 ms |
26364 KB |
Output is correct |
30 |
Correct |
261 ms |
19252 KB |
Output is correct |
31 |
Correct |
361 ms |
26716 KB |
Output is correct |
32 |
Correct |
345 ms |
23996 KB |
Output is correct |
33 |
Correct |
250 ms |
17964 KB |
Output is correct |
34 |
Correct |
339 ms |
24464 KB |
Output is correct |
35 |
Correct |
285 ms |
23756 KB |
Output is correct |
36 |
Correct |
248 ms |
18156 KB |
Output is correct |
37 |
Correct |
262 ms |
18040 KB |
Output is correct |
38 |
Correct |
330 ms |
21452 KB |
Output is correct |
39 |
Correct |
244 ms |
20172 KB |
Output is correct |
40 |
Correct |
308 ms |
21492 KB |
Output is correct |
41 |
Correct |
291 ms |
14540 KB |
Output is correct |
42 |
Correct |
87 ms |
13200 KB |
Output is correct |
43 |
Correct |
190 ms |
15188 KB |
Output is correct |
44 |
Correct |
146 ms |
9312 KB |
Output is correct |
45 |
Correct |
187 ms |
16588 KB |
Output is correct |
46 |
Correct |
160 ms |
14548 KB |
Output is correct |
47 |
Correct |
194 ms |
16600 KB |
Output is correct |
48 |
Correct |
182 ms |
15380 KB |
Output is correct |
49 |
Correct |
198 ms |
16580 KB |
Output is correct |
50 |
Correct |
171 ms |
15160 KB |
Output is correct |
51 |
Correct |
189 ms |
16584 KB |
Output is correct |
52 |
Correct |
172 ms |
15332 KB |
Output is correct |
53 |
Correct |
188 ms |
15952 KB |
Output is correct |
54 |
Correct |
160 ms |
14768 KB |
Output is correct |
55 |
Correct |
196 ms |
16760 KB |
Output is correct |
56 |
Correct |
194 ms |
16576 KB |
Output is correct |
57 |
Correct |
185 ms |
16084 KB |
Output is correct |
58 |
Correct |
176 ms |
15212 KB |
Output is correct |
59 |
Correct |
198 ms |
17148 KB |
Output is correct |
60 |
Correct |
187 ms |
16420 KB |
Output is correct |
61 |
Correct |
208 ms |
17140 KB |
Output is correct |
62 |
Correct |
183 ms |
16588 KB |
Output is correct |
63 |
Correct |
195 ms |
17172 KB |
Output is correct |
64 |
Correct |
190 ms |
16304 KB |
Output is correct |
65 |
Correct |
204 ms |
17216 KB |
Output is correct |
66 |
Correct |
191 ms |
16340 KB |
Output is correct |
67 |
Correct |
177 ms |
15708 KB |
Output is correct |
68 |
Correct |
187 ms |
16092 KB |
Output is correct |
69 |
Correct |
327 ms |
22352 KB |
Output is correct |
70 |
Correct |
376 ms |
24336 KB |
Output is correct |
71 |
Correct |
247 ms |
18064 KB |
Output is correct |
72 |
Correct |
238 ms |
18128 KB |
Output is correct |
73 |
Correct |
234 ms |
18112 KB |
Output is correct |
74 |
Correct |
310 ms |
24372 KB |
Output is correct |
75 |
Correct |
251 ms |
19296 KB |
Output is correct |
76 |
Correct |
326 ms |
26272 KB |
Output is correct |
77 |
Correct |
309 ms |
23096 KB |
Output is correct |
78 |
Correct |
260 ms |
18072 KB |
Output is correct |
79 |
Correct |
246 ms |
17976 KB |
Output is correct |
80 |
Correct |
288 ms |
23644 KB |
Output is correct |
81 |
Correct |
252 ms |
19264 KB |
Output is correct |
82 |
Correct |
372 ms |
26432 KB |
Output is correct |
83 |
Correct |
314 ms |
23792 KB |
Output is correct |
84 |
Correct |
251 ms |
17972 KB |
Output is correct |
85 |
Correct |
257 ms |
18148 KB |
Output is correct |
86 |
Correct |
323 ms |
22804 KB |
Output is correct |
87 |
Correct |
344 ms |
24432 KB |
Output is correct |
88 |
Correct |
241 ms |
17284 KB |
Output is correct |
89 |
Correct |
328 ms |
23328 KB |
Output is correct |
90 |
Correct |
337 ms |
24640 KB |
Output is correct |
91 |
Correct |
248 ms |
17452 KB |
Output is correct |
92 |
Correct |
374 ms |
23696 KB |
Output is correct |
93 |
Correct |
307 ms |
18200 KB |
Output is correct |
94 |
Correct |
311 ms |
18124 KB |
Output is correct |
95 |
Correct |
300 ms |
18032 KB |
Output is correct |
96 |
Correct |
388 ms |
21408 KB |
Output is correct |
97 |
Correct |
274 ms |
21588 KB |
Output is correct |
98 |
Correct |
339 ms |
21456 KB |
Output is correct |
99 |
Correct |
300 ms |
14492 KB |
Output is correct |
100 |
Correct |
89 ms |
13116 KB |
Output is correct |