#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
#define base 5
#define mod 1000000007
int n,q,l,r;
ll val[4][200005],pw[200005];
char c;
vector<vi> v;
set<ll> h;
struct node{
int s,e,m,lz;ll v;
node *l,*r;
node(int _s,int _e){
s=_s;e=_e;m=(s+e)/2;lz=0;v=0;
if(s!=e)l=new node(s,m),r=new node(m+1,e);
}
void ppo(){
if(lz==0)return;
v=val[lz][(e-s+1)];
if(s!=e)l->lz=lz,r->lz=lz;
lz=0;
}
void up(int x,int y,int nv){
ppo();
if(s==x&&e==y){
lz=nv;return;
}
if(y<=m)l->up(x,y,nv);
else if(x>m)r->up(x,y,nv);
else l->up(x,m,nv),r->up(m+1,y,nv);
l->ppo();r->ppo();
v=(l->v*pw[r->e-r->s+1]+r->v)%mod;
}
ll qry(){
ppo();return v;
}
}*root;
int to(char c){
if(c=='J')return 0;
else if(c=='O')return 1;
else return 2;
}
int main(){
sf("%d",&n);
for(int j=0;j<3;++j){
v.push_back(vi());
for(int i=0;i<n;++i){
scanf(" %c",&c);
int x=to(c);
v.back().pb(x);
}
}
for(int i=-2;i<=2;++i){
for(int j=-2;j<=2;++j){
for(int k=-2;k<=2;++k){
if((i+j+k)%3!=1)continue;
v.push_back(vi());
for(int l=0;l<n;++l){
int nw=v[0][l]*i+v[1][l]*j+v[2][l]*k+9;
v.back().pb(nw%3);
}
}
}
}
for(vi x:v){
ll hash=0;
for(int i=0;i<n;++i){
hash*=base;
hash+=(x[i]+1);
hash%=mod;
}
h.insert(hash);
}
for(int i=1;i<=3;++i){
for(int j=1;j<=n;++j){
val[i][j]=(val[i][j-1]*base+i)%mod;
}
}
pw[0]=1;
for(int i=1;i<=n;++i)pw[i]=(pw[i-1]*base)%mod;
root=new node(0,n-1);
sf("%d",&q);
for(int i=0;i<n;++i){
sf(" %c",&c);
int x=to(c)+1;
root->up(i,i,x);
}
if(h.count(root->qry()))pf("Yes\n");
else pf("No\n");
for(int i=0;i<q;++i){
sf("%d%d",&l,&r);
sf(" %c",&c);
int x=to(c)+1;
root->up(l-1,r-1,x);
if(h.count(root->qry()))pf("Yes\n");
else pf("No\n");
}
}
/*
4
JOJO
JJOI
OJOO
3
IJOJ
1 4 O
2 2 J
2 4 I
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:86:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | sf("%d",&n);
| ^
Main.cpp:90:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | scanf(" %c",&c);
| ~~~~~^~~~~~~~~~
Main.cpp:124:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
124 | sf("%d",&q);
| ^
Main.cpp:126:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
126 | sf(" %c",&c);
| ^
Main.cpp:133:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
133 | sf("%d%d",&l,&r);
| ^
Main.cpp:134:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | sf(" %c",&c);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
824 KB |
Output is correct |
2 |
Correct |
107 ms |
888 KB |
Output is correct |
3 |
Correct |
104 ms |
932 KB |
Output is correct |
4 |
Correct |
91 ms |
852 KB |
Output is correct |
5 |
Correct |
87 ms |
860 KB |
Output is correct |
6 |
Correct |
85 ms |
788 KB |
Output is correct |
7 |
Correct |
94 ms |
928 KB |
Output is correct |
8 |
Correct |
92 ms |
896 KB |
Output is correct |
9 |
Correct |
96 ms |
936 KB |
Output is correct |
10 |
Correct |
97 ms |
872 KB |
Output is correct |
11 |
Correct |
99 ms |
860 KB |
Output is correct |
12 |
Correct |
91 ms |
920 KB |
Output is correct |
13 |
Correct |
92 ms |
848 KB |
Output is correct |
14 |
Correct |
93 ms |
860 KB |
Output is correct |
15 |
Correct |
102 ms |
808 KB |
Output is correct |
16 |
Correct |
100 ms |
836 KB |
Output is correct |
17 |
Correct |
97 ms |
880 KB |
Output is correct |
18 |
Correct |
110 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
824 KB |
Output is correct |
2 |
Correct |
107 ms |
888 KB |
Output is correct |
3 |
Correct |
104 ms |
932 KB |
Output is correct |
4 |
Correct |
91 ms |
852 KB |
Output is correct |
5 |
Correct |
87 ms |
860 KB |
Output is correct |
6 |
Correct |
85 ms |
788 KB |
Output is correct |
7 |
Correct |
94 ms |
928 KB |
Output is correct |
8 |
Correct |
92 ms |
896 KB |
Output is correct |
9 |
Correct |
96 ms |
936 KB |
Output is correct |
10 |
Correct |
97 ms |
872 KB |
Output is correct |
11 |
Correct |
99 ms |
860 KB |
Output is correct |
12 |
Correct |
91 ms |
920 KB |
Output is correct |
13 |
Correct |
92 ms |
848 KB |
Output is correct |
14 |
Correct |
93 ms |
860 KB |
Output is correct |
15 |
Correct |
102 ms |
808 KB |
Output is correct |
16 |
Correct |
100 ms |
836 KB |
Output is correct |
17 |
Correct |
97 ms |
880 KB |
Output is correct |
18 |
Correct |
110 ms |
888 KB |
Output is correct |
19 |
Correct |
581 ms |
47048 KB |
Output is correct |
20 |
Correct |
567 ms |
47084 KB |
Output is correct |
21 |
Correct |
416 ms |
44320 KB |
Output is correct |
22 |
Correct |
398 ms |
39832 KB |
Output is correct |
23 |
Correct |
155 ms |
3352 KB |
Output is correct |
24 |
Correct |
150 ms |
3288 KB |
Output is correct |
25 |
Correct |
462 ms |
47248 KB |
Output is correct |
26 |
Correct |
475 ms |
47196 KB |
Output is correct |
27 |
Correct |
524 ms |
47112 KB |
Output is correct |
28 |
Correct |
563 ms |
47432 KB |
Output is correct |
29 |
Correct |
500 ms |
45744 KB |
Output is correct |
30 |
Correct |
172 ms |
3368 KB |
Output is correct |
31 |
Correct |
521 ms |
47188 KB |
Output is correct |
32 |
Correct |
482 ms |
43044 KB |
Output is correct |
33 |
Correct |
154 ms |
3340 KB |
Output is correct |
34 |
Correct |
506 ms |
47108 KB |
Output is correct |
35 |
Correct |
382 ms |
35380 KB |
Output is correct |
36 |
Correct |
160 ms |
3268 KB |
Output is correct |
37 |
Correct |
163 ms |
3332 KB |
Output is correct |
38 |
Correct |
472 ms |
47096 KB |
Output is correct |
39 |
Correct |
335 ms |
47204 KB |
Output is correct |
40 |
Correct |
397 ms |
31340 KB |
Output is correct |
41 |
Correct |
661 ms |
47344 KB |
Output is correct |
42 |
Correct |
265 ms |
47356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
824 KB |
Output is correct |
2 |
Correct |
107 ms |
888 KB |
Output is correct |
3 |
Correct |
104 ms |
932 KB |
Output is correct |
4 |
Correct |
91 ms |
852 KB |
Output is correct |
5 |
Correct |
87 ms |
860 KB |
Output is correct |
6 |
Correct |
85 ms |
788 KB |
Output is correct |
7 |
Correct |
94 ms |
928 KB |
Output is correct |
8 |
Correct |
92 ms |
896 KB |
Output is correct |
9 |
Correct |
96 ms |
936 KB |
Output is correct |
10 |
Correct |
97 ms |
872 KB |
Output is correct |
11 |
Correct |
99 ms |
860 KB |
Output is correct |
12 |
Correct |
91 ms |
920 KB |
Output is correct |
13 |
Correct |
92 ms |
848 KB |
Output is correct |
14 |
Correct |
93 ms |
860 KB |
Output is correct |
15 |
Correct |
102 ms |
808 KB |
Output is correct |
16 |
Correct |
100 ms |
836 KB |
Output is correct |
17 |
Correct |
97 ms |
880 KB |
Output is correct |
18 |
Correct |
110 ms |
888 KB |
Output is correct |
19 |
Correct |
106 ms |
788 KB |
Output is correct |
20 |
Correct |
116 ms |
876 KB |
Output is correct |
21 |
Correct |
96 ms |
856 KB |
Output is correct |
22 |
Correct |
88 ms |
836 KB |
Output is correct |
23 |
Correct |
94 ms |
828 KB |
Output is correct |
24 |
Correct |
90 ms |
788 KB |
Output is correct |
25 |
Correct |
94 ms |
884 KB |
Output is correct |
26 |
Correct |
106 ms |
836 KB |
Output is correct |
27 |
Correct |
119 ms |
916 KB |
Output is correct |
28 |
Correct |
84 ms |
756 KB |
Output is correct |
29 |
Correct |
101 ms |
836 KB |
Output is correct |
30 |
Correct |
86 ms |
940 KB |
Output is correct |
31 |
Correct |
100 ms |
928 KB |
Output is correct |
32 |
Correct |
98 ms |
836 KB |
Output is correct |
33 |
Correct |
97 ms |
900 KB |
Output is correct |
34 |
Correct |
89 ms |
852 KB |
Output is correct |
35 |
Correct |
97 ms |
872 KB |
Output is correct |
36 |
Correct |
101 ms |
940 KB |
Output is correct |
37 |
Correct |
97 ms |
908 KB |
Output is correct |
38 |
Correct |
98 ms |
824 KB |
Output is correct |
39 |
Correct |
104 ms |
856 KB |
Output is correct |
40 |
Correct |
121 ms |
836 KB |
Output is correct |
41 |
Correct |
94 ms |
856 KB |
Output is correct |
42 |
Correct |
102 ms |
860 KB |
Output is correct |
43 |
Correct |
95 ms |
828 KB |
Output is correct |
44 |
Correct |
108 ms |
880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
824 KB |
Output is correct |
2 |
Correct |
107 ms |
888 KB |
Output is correct |
3 |
Correct |
104 ms |
932 KB |
Output is correct |
4 |
Correct |
91 ms |
852 KB |
Output is correct |
5 |
Correct |
87 ms |
860 KB |
Output is correct |
6 |
Correct |
85 ms |
788 KB |
Output is correct |
7 |
Correct |
94 ms |
928 KB |
Output is correct |
8 |
Correct |
92 ms |
896 KB |
Output is correct |
9 |
Correct |
96 ms |
936 KB |
Output is correct |
10 |
Correct |
97 ms |
872 KB |
Output is correct |
11 |
Correct |
99 ms |
860 KB |
Output is correct |
12 |
Correct |
91 ms |
920 KB |
Output is correct |
13 |
Correct |
92 ms |
848 KB |
Output is correct |
14 |
Correct |
93 ms |
860 KB |
Output is correct |
15 |
Correct |
102 ms |
808 KB |
Output is correct |
16 |
Correct |
100 ms |
836 KB |
Output is correct |
17 |
Correct |
97 ms |
880 KB |
Output is correct |
18 |
Correct |
110 ms |
888 KB |
Output is correct |
19 |
Correct |
581 ms |
47048 KB |
Output is correct |
20 |
Correct |
567 ms |
47084 KB |
Output is correct |
21 |
Correct |
416 ms |
44320 KB |
Output is correct |
22 |
Correct |
398 ms |
39832 KB |
Output is correct |
23 |
Correct |
155 ms |
3352 KB |
Output is correct |
24 |
Correct |
150 ms |
3288 KB |
Output is correct |
25 |
Correct |
462 ms |
47248 KB |
Output is correct |
26 |
Correct |
475 ms |
47196 KB |
Output is correct |
27 |
Correct |
524 ms |
47112 KB |
Output is correct |
28 |
Correct |
563 ms |
47432 KB |
Output is correct |
29 |
Correct |
500 ms |
45744 KB |
Output is correct |
30 |
Correct |
172 ms |
3368 KB |
Output is correct |
31 |
Correct |
521 ms |
47188 KB |
Output is correct |
32 |
Correct |
482 ms |
43044 KB |
Output is correct |
33 |
Correct |
154 ms |
3340 KB |
Output is correct |
34 |
Correct |
506 ms |
47108 KB |
Output is correct |
35 |
Correct |
382 ms |
35380 KB |
Output is correct |
36 |
Correct |
160 ms |
3268 KB |
Output is correct |
37 |
Correct |
163 ms |
3332 KB |
Output is correct |
38 |
Correct |
472 ms |
47096 KB |
Output is correct |
39 |
Correct |
335 ms |
47204 KB |
Output is correct |
40 |
Correct |
397 ms |
31340 KB |
Output is correct |
41 |
Correct |
661 ms |
47344 KB |
Output is correct |
42 |
Correct |
265 ms |
47356 KB |
Output is correct |
43 |
Correct |
106 ms |
788 KB |
Output is correct |
44 |
Correct |
116 ms |
876 KB |
Output is correct |
45 |
Correct |
96 ms |
856 KB |
Output is correct |
46 |
Correct |
88 ms |
836 KB |
Output is correct |
47 |
Correct |
94 ms |
828 KB |
Output is correct |
48 |
Correct |
90 ms |
788 KB |
Output is correct |
49 |
Correct |
94 ms |
884 KB |
Output is correct |
50 |
Correct |
106 ms |
836 KB |
Output is correct |
51 |
Correct |
119 ms |
916 KB |
Output is correct |
52 |
Correct |
84 ms |
756 KB |
Output is correct |
53 |
Correct |
101 ms |
836 KB |
Output is correct |
54 |
Correct |
86 ms |
940 KB |
Output is correct |
55 |
Correct |
100 ms |
928 KB |
Output is correct |
56 |
Correct |
98 ms |
836 KB |
Output is correct |
57 |
Correct |
97 ms |
900 KB |
Output is correct |
58 |
Correct |
89 ms |
852 KB |
Output is correct |
59 |
Correct |
97 ms |
872 KB |
Output is correct |
60 |
Correct |
101 ms |
940 KB |
Output is correct |
61 |
Correct |
97 ms |
908 KB |
Output is correct |
62 |
Correct |
98 ms |
824 KB |
Output is correct |
63 |
Correct |
104 ms |
856 KB |
Output is correct |
64 |
Correct |
121 ms |
836 KB |
Output is correct |
65 |
Correct |
94 ms |
856 KB |
Output is correct |
66 |
Correct |
102 ms |
860 KB |
Output is correct |
67 |
Correct |
95 ms |
828 KB |
Output is correct |
68 |
Correct |
108 ms |
880 KB |
Output is correct |
69 |
Correct |
529 ms |
39508 KB |
Output is correct |
70 |
Correct |
487 ms |
47188 KB |
Output is correct |
71 |
Correct |
171 ms |
3268 KB |
Output is correct |
72 |
Correct |
157 ms |
3548 KB |
Output is correct |
73 |
Correct |
156 ms |
3396 KB |
Output is correct |
74 |
Correct |
397 ms |
39504 KB |
Output is correct |
75 |
Correct |
148 ms |
3268 KB |
Output is correct |
76 |
Correct |
440 ms |
47048 KB |
Output is correct |
77 |
Correct |
432 ms |
39516 KB |
Output is correct |
78 |
Correct |
152 ms |
3284 KB |
Output is correct |
79 |
Correct |
170 ms |
3328 KB |
Output is correct |
80 |
Correct |
372 ms |
33752 KB |
Output is correct |
81 |
Correct |
172 ms |
3296 KB |
Output is correct |
82 |
Correct |
440 ms |
47164 KB |
Output is correct |
83 |
Correct |
461 ms |
44348 KB |
Output is correct |
84 |
Correct |
156 ms |
3268 KB |
Output is correct |
85 |
Correct |
155 ms |
3324 KB |
Output is correct |
86 |
Correct |
463 ms |
36000 KB |
Output is correct |
87 |
Correct |
520 ms |
47056 KB |
Output is correct |
88 |
Correct |
161 ms |
3272 KB |
Output is correct |
89 |
Correct |
464 ms |
41592 KB |
Output is correct |
90 |
Correct |
492 ms |
47144 KB |
Output is correct |
91 |
Correct |
165 ms |
3288 KB |
Output is correct |
92 |
Correct |
372 ms |
35508 KB |
Output is correct |
93 |
Correct |
170 ms |
3268 KB |
Output is correct |
94 |
Correct |
150 ms |
3244 KB |
Output is correct |
95 |
Correct |
149 ms |
3404 KB |
Output is correct |
96 |
Correct |
445 ms |
47172 KB |
Output is correct |
97 |
Correct |
332 ms |
47132 KB |
Output is correct |
98 |
Correct |
391 ms |
31236 KB |
Output is correct |
99 |
Correct |
599 ms |
47356 KB |
Output is correct |
100 |
Correct |
262 ms |
47300 KB |
Output is correct |