#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rrep(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;i--)
using ll=long long;
using namespace std;
using ull=unsigned long long;
vector<ull>pw(400000),pw2(400000);
static constexpr ull MOD=(1LL<<61)-1;
static constexpr ull inv2=(1LL<<60);
static constexpr ull base=2199866433;
ull mul(ull a,ull b){
return __uint128_t(a)*b%MOD;
}
ull add(ull a,ull b){
a+=b;if(a>=MOD)a-=MOD;
return a;
}
ull div2(ull a){
return mul(a,inv2);
}
void init(){
pw[0]=1;
rep(i,1,pw.size())pw[i]=mul(base,pw[i-1]);
pw2[0]=0;
rep(i,1,pw2.size())pw2[i]=add(pw2[i-1],pw[i-1]);
}
int get_id(char c){
if(c=='J')return 0;
if(c=='O')return 1;
return 2;
}
char from_id(int a){
if(a==0)return 'J';
if(a==1)return 'O';
return 'I';
}
struct segment_rolling_hash{
private:
int n,sz,lg;
vector<pair<ull,ll>>seg;
vector<int>lazy;
void all_apply(int k,int a){
seg[k].first=mul(a,pw2[seg[k].second]);
if(k<sz)lazy[k]=a;
}
void push(int k){
if(lazy[k]==-1)return;
all_apply(k<<1,lazy[k]);all_apply(k<<1|1,lazy[k]);
lazy[k]=-1;
}
void update(int i){
seg[i].first=add(mul(seg[i<<1].first,pw[seg[i<<1|1].second]),seg[i<<1|1].first);
seg[i].second=seg[i<<1].second+seg[i<<1|1].second;
}
public:
segment_rolling_hash(string s):n(s.size()){
sz=1,lg=0;
while(sz<n)sz<<=1,lg++;
seg.resize(sz<<1);
rep(i,0,n){
seg[i+sz].second=1;
seg[i+sz].first=get_id(s[i]);
}
rrep(i,1,sz)update(i);
lazy.assign(sz,-1);
}
void apply(int l,int r,int a){
l+=sz,r+=sz;
rrep(i,1,lg+1){
if(((l>>i)<<i)!=l)push(l>>i);
if(((r>>i)<<i)!=r)push((r-1)>>i);
}
for(int l2=l,r2=r;l2<r2;l2>>=1,r2>>=1){
if(l2&1)all_apply(l2++,a);
if(r2&1)all_apply(--r2,a);
}
rep(i,0,lg+1){
if(((l>>i)<<i)!=l)update(l>>i);
if(((r>>i)<<i)!=r)update((r-1)>>i);
}
}
ull all_prod()const{return seg[1].first;}
};
ull get_hash(string a){
ull hash=0;
for(auto i:a){
hash=mul(hash,base);
hash=add(hash,get_id(i));
}
return hash;
}
string f(string a,string b){
assert(a.size()==b.size());
string ans(a.size(),'1');
rep(i,0,a.size()){
if(get_id(a[i])==get_id(b[i]))ans[i]=a[i];
else ans[i]=from_id(3^get_id(a[i])^get_id(b[i]));
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int n;cin>>n;
string a,b,c;cin>>a>>b>>c;
//cerr<<a<<" "<<b<<" "<<c<<endl;
string ab=f(a,b),bc=f(b,c),ac=f(a,c),abbc=f(ab,bc),abac=f(ab,ac),bcac=f(bc,ac);
//cerr<<ab<<" "<<bc<<" "<<ac<<endl;
//cerr<<abbc<<" "<<abac<<" "<<bcac<<endl;
set<ull>st;
st.insert(get_hash(a));
st.insert(get_hash(b));
st.insert(get_hash(c));
st.insert(get_hash(ab));
st.insert(get_hash(bc));
st.insert(get_hash(ac));
st.insert(get_hash(abbc));
st.insert(get_hash(abac));
st.insert(get_hash(bcac));
//for(auto i:st)cerr<<i<<endl;
int q;cin>>q;
string t;cin>>t;
segment_rolling_hash seg(t);
if(st.count(seg.all_prod())){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
rep(i,0,q){
int l,r;char c;
cin>>l>>r>>c;
l--;
seg.apply(l,r,get_id(c));
//cerr<<seg.all_prod()<<endl;
if(st.count(seg.all_prod())){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
7092 KB |
Output is correct |
2 |
Correct |
310 ms |
7240 KB |
Output is correct |
3 |
Correct |
304 ms |
7076 KB |
Output is correct |
4 |
Correct |
287 ms |
7096 KB |
Output is correct |
5 |
Correct |
286 ms |
7140 KB |
Output is correct |
6 |
Correct |
281 ms |
7128 KB |
Output is correct |
7 |
Correct |
293 ms |
7116 KB |
Output is correct |
8 |
Correct |
307 ms |
7172 KB |
Output is correct |
9 |
Correct |
300 ms |
7092 KB |
Output is correct |
10 |
Correct |
296 ms |
7420 KB |
Output is correct |
11 |
Correct |
306 ms |
7124 KB |
Output is correct |
12 |
Correct |
298 ms |
7244 KB |
Output is correct |
13 |
Correct |
301 ms |
7116 KB |
Output is correct |
14 |
Correct |
297 ms |
7132 KB |
Output is correct |
15 |
Correct |
303 ms |
7116 KB |
Output is correct |
16 |
Correct |
298 ms |
7116 KB |
Output is correct |
17 |
Correct |
304 ms |
7116 KB |
Output is correct |
18 |
Correct |
304 ms |
7256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
7092 KB |
Output is correct |
2 |
Correct |
310 ms |
7240 KB |
Output is correct |
3 |
Correct |
304 ms |
7076 KB |
Output is correct |
4 |
Correct |
287 ms |
7096 KB |
Output is correct |
5 |
Correct |
286 ms |
7140 KB |
Output is correct |
6 |
Correct |
281 ms |
7128 KB |
Output is correct |
7 |
Correct |
293 ms |
7116 KB |
Output is correct |
8 |
Correct |
307 ms |
7172 KB |
Output is correct |
9 |
Correct |
300 ms |
7092 KB |
Output is correct |
10 |
Correct |
296 ms |
7420 KB |
Output is correct |
11 |
Correct |
306 ms |
7124 KB |
Output is correct |
12 |
Correct |
298 ms |
7244 KB |
Output is correct |
13 |
Correct |
301 ms |
7116 KB |
Output is correct |
14 |
Correct |
297 ms |
7132 KB |
Output is correct |
15 |
Correct |
303 ms |
7116 KB |
Output is correct |
16 |
Correct |
298 ms |
7116 KB |
Output is correct |
17 |
Correct |
304 ms |
7116 KB |
Output is correct |
18 |
Correct |
304 ms |
7256 KB |
Output is correct |
19 |
Correct |
525 ms |
18788 KB |
Output is correct |
20 |
Correct |
498 ms |
18732 KB |
Output is correct |
21 |
Correct |
420 ms |
18576 KB |
Output is correct |
22 |
Correct |
414 ms |
18336 KB |
Output is correct |
23 |
Correct |
361 ms |
8008 KB |
Output is correct |
24 |
Correct |
366 ms |
7872 KB |
Output is correct |
25 |
Correct |
448 ms |
18820 KB |
Output is correct |
26 |
Correct |
458 ms |
18776 KB |
Output is correct |
27 |
Correct |
448 ms |
18716 KB |
Output is correct |
28 |
Correct |
458 ms |
19028 KB |
Output is correct |
29 |
Correct |
436 ms |
18616 KB |
Output is correct |
30 |
Correct |
372 ms |
8008 KB |
Output is correct |
31 |
Correct |
439 ms |
18780 KB |
Output is correct |
32 |
Correct |
454 ms |
18648 KB |
Output is correct |
33 |
Correct |
365 ms |
7884 KB |
Output is correct |
34 |
Correct |
459 ms |
18736 KB |
Output is correct |
35 |
Correct |
409 ms |
18168 KB |
Output is correct |
36 |
Correct |
362 ms |
7868 KB |
Output is correct |
37 |
Correct |
360 ms |
7864 KB |
Output is correct |
38 |
Correct |
463 ms |
18764 KB |
Output is correct |
39 |
Correct |
424 ms |
18732 KB |
Output is correct |
40 |
Correct |
419 ms |
13324 KB |
Output is correct |
41 |
Correct |
468 ms |
18996 KB |
Output is correct |
42 |
Correct |
310 ms |
18884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
7092 KB |
Output is correct |
2 |
Correct |
310 ms |
7240 KB |
Output is correct |
3 |
Correct |
304 ms |
7076 KB |
Output is correct |
4 |
Correct |
287 ms |
7096 KB |
Output is correct |
5 |
Correct |
286 ms |
7140 KB |
Output is correct |
6 |
Correct |
281 ms |
7128 KB |
Output is correct |
7 |
Correct |
293 ms |
7116 KB |
Output is correct |
8 |
Correct |
307 ms |
7172 KB |
Output is correct |
9 |
Correct |
300 ms |
7092 KB |
Output is correct |
10 |
Correct |
296 ms |
7420 KB |
Output is correct |
11 |
Correct |
306 ms |
7124 KB |
Output is correct |
12 |
Correct |
298 ms |
7244 KB |
Output is correct |
13 |
Correct |
301 ms |
7116 KB |
Output is correct |
14 |
Correct |
297 ms |
7132 KB |
Output is correct |
15 |
Correct |
303 ms |
7116 KB |
Output is correct |
16 |
Correct |
298 ms |
7116 KB |
Output is correct |
17 |
Correct |
304 ms |
7116 KB |
Output is correct |
18 |
Correct |
304 ms |
7256 KB |
Output is correct |
19 |
Correct |
295 ms |
7060 KB |
Output is correct |
20 |
Correct |
305 ms |
7156 KB |
Output is correct |
21 |
Correct |
297 ms |
7340 KB |
Output is correct |
22 |
Correct |
274 ms |
7116 KB |
Output is correct |
23 |
Correct |
303 ms |
7280 KB |
Output is correct |
24 |
Correct |
290 ms |
7108 KB |
Output is correct |
25 |
Correct |
306 ms |
7180 KB |
Output is correct |
26 |
Correct |
289 ms |
7112 KB |
Output is correct |
27 |
Correct |
301 ms |
7068 KB |
Output is correct |
28 |
Correct |
274 ms |
7128 KB |
Output is correct |
29 |
Correct |
307 ms |
7212 KB |
Output is correct |
30 |
Correct |
283 ms |
7204 KB |
Output is correct |
31 |
Correct |
301 ms |
7184 KB |
Output is correct |
32 |
Correct |
294 ms |
7280 KB |
Output is correct |
33 |
Correct |
303 ms |
7128 KB |
Output is correct |
34 |
Correct |
297 ms |
7144 KB |
Output is correct |
35 |
Correct |
301 ms |
7096 KB |
Output is correct |
36 |
Correct |
313 ms |
7244 KB |
Output is correct |
37 |
Correct |
305 ms |
7180 KB |
Output is correct |
38 |
Correct |
305 ms |
7100 KB |
Output is correct |
39 |
Correct |
319 ms |
7184 KB |
Output is correct |
40 |
Correct |
308 ms |
7164 KB |
Output is correct |
41 |
Correct |
304 ms |
7180 KB |
Output is correct |
42 |
Correct |
320 ms |
7128 KB |
Output is correct |
43 |
Correct |
297 ms |
7148 KB |
Output is correct |
44 |
Correct |
303 ms |
7104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
7092 KB |
Output is correct |
2 |
Correct |
310 ms |
7240 KB |
Output is correct |
3 |
Correct |
304 ms |
7076 KB |
Output is correct |
4 |
Correct |
287 ms |
7096 KB |
Output is correct |
5 |
Correct |
286 ms |
7140 KB |
Output is correct |
6 |
Correct |
281 ms |
7128 KB |
Output is correct |
7 |
Correct |
293 ms |
7116 KB |
Output is correct |
8 |
Correct |
307 ms |
7172 KB |
Output is correct |
9 |
Correct |
300 ms |
7092 KB |
Output is correct |
10 |
Correct |
296 ms |
7420 KB |
Output is correct |
11 |
Correct |
306 ms |
7124 KB |
Output is correct |
12 |
Correct |
298 ms |
7244 KB |
Output is correct |
13 |
Correct |
301 ms |
7116 KB |
Output is correct |
14 |
Correct |
297 ms |
7132 KB |
Output is correct |
15 |
Correct |
303 ms |
7116 KB |
Output is correct |
16 |
Correct |
298 ms |
7116 KB |
Output is correct |
17 |
Correct |
304 ms |
7116 KB |
Output is correct |
18 |
Correct |
304 ms |
7256 KB |
Output is correct |
19 |
Correct |
525 ms |
18788 KB |
Output is correct |
20 |
Correct |
498 ms |
18732 KB |
Output is correct |
21 |
Correct |
420 ms |
18576 KB |
Output is correct |
22 |
Correct |
414 ms |
18336 KB |
Output is correct |
23 |
Correct |
361 ms |
8008 KB |
Output is correct |
24 |
Correct |
366 ms |
7872 KB |
Output is correct |
25 |
Correct |
448 ms |
18820 KB |
Output is correct |
26 |
Correct |
458 ms |
18776 KB |
Output is correct |
27 |
Correct |
448 ms |
18716 KB |
Output is correct |
28 |
Correct |
458 ms |
19028 KB |
Output is correct |
29 |
Correct |
436 ms |
18616 KB |
Output is correct |
30 |
Correct |
372 ms |
8008 KB |
Output is correct |
31 |
Correct |
439 ms |
18780 KB |
Output is correct |
32 |
Correct |
454 ms |
18648 KB |
Output is correct |
33 |
Correct |
365 ms |
7884 KB |
Output is correct |
34 |
Correct |
459 ms |
18736 KB |
Output is correct |
35 |
Correct |
409 ms |
18168 KB |
Output is correct |
36 |
Correct |
362 ms |
7868 KB |
Output is correct |
37 |
Correct |
360 ms |
7864 KB |
Output is correct |
38 |
Correct |
463 ms |
18764 KB |
Output is correct |
39 |
Correct |
424 ms |
18732 KB |
Output is correct |
40 |
Correct |
419 ms |
13324 KB |
Output is correct |
41 |
Correct |
468 ms |
18996 KB |
Output is correct |
42 |
Correct |
310 ms |
18884 KB |
Output is correct |
43 |
Correct |
295 ms |
7060 KB |
Output is correct |
44 |
Correct |
305 ms |
7156 KB |
Output is correct |
45 |
Correct |
297 ms |
7340 KB |
Output is correct |
46 |
Correct |
274 ms |
7116 KB |
Output is correct |
47 |
Correct |
303 ms |
7280 KB |
Output is correct |
48 |
Correct |
290 ms |
7108 KB |
Output is correct |
49 |
Correct |
306 ms |
7180 KB |
Output is correct |
50 |
Correct |
289 ms |
7112 KB |
Output is correct |
51 |
Correct |
301 ms |
7068 KB |
Output is correct |
52 |
Correct |
274 ms |
7128 KB |
Output is correct |
53 |
Correct |
307 ms |
7212 KB |
Output is correct |
54 |
Correct |
283 ms |
7204 KB |
Output is correct |
55 |
Correct |
301 ms |
7184 KB |
Output is correct |
56 |
Correct |
294 ms |
7280 KB |
Output is correct |
57 |
Correct |
303 ms |
7128 KB |
Output is correct |
58 |
Correct |
297 ms |
7144 KB |
Output is correct |
59 |
Correct |
301 ms |
7096 KB |
Output is correct |
60 |
Correct |
313 ms |
7244 KB |
Output is correct |
61 |
Correct |
305 ms |
7180 KB |
Output is correct |
62 |
Correct |
305 ms |
7100 KB |
Output is correct |
63 |
Correct |
319 ms |
7184 KB |
Output is correct |
64 |
Correct |
308 ms |
7164 KB |
Output is correct |
65 |
Correct |
304 ms |
7180 KB |
Output is correct |
66 |
Correct |
320 ms |
7128 KB |
Output is correct |
67 |
Correct |
297 ms |
7148 KB |
Output is correct |
68 |
Correct |
303 ms |
7104 KB |
Output is correct |
69 |
Correct |
476 ms |
18276 KB |
Output is correct |
70 |
Correct |
503 ms |
18776 KB |
Output is correct |
71 |
Correct |
362 ms |
7848 KB |
Output is correct |
72 |
Correct |
361 ms |
7964 KB |
Output is correct |
73 |
Correct |
366 ms |
7864 KB |
Output is correct |
74 |
Correct |
433 ms |
18376 KB |
Output is correct |
75 |
Correct |
363 ms |
7828 KB |
Output is correct |
76 |
Correct |
473 ms |
18828 KB |
Output is correct |
77 |
Correct |
435 ms |
18308 KB |
Output is correct |
78 |
Correct |
377 ms |
7812 KB |
Output is correct |
79 |
Correct |
362 ms |
7880 KB |
Output is correct |
80 |
Correct |
421 ms |
18016 KB |
Output is correct |
81 |
Correct |
362 ms |
7856 KB |
Output is correct |
82 |
Correct |
453 ms |
18740 KB |
Output is correct |
83 |
Correct |
459 ms |
18568 KB |
Output is correct |
84 |
Correct |
367 ms |
7824 KB |
Output is correct |
85 |
Correct |
382 ms |
7920 KB |
Output is correct |
86 |
Correct |
439 ms |
18220 KB |
Output is correct |
87 |
Correct |
486 ms |
18968 KB |
Output is correct |
88 |
Correct |
375 ms |
8004 KB |
Output is correct |
89 |
Correct |
427 ms |
18376 KB |
Output is correct |
90 |
Correct |
457 ms |
18964 KB |
Output is correct |
91 |
Correct |
372 ms |
7808 KB |
Output is correct |
92 |
Correct |
437 ms |
18200 KB |
Output is correct |
93 |
Correct |
367 ms |
7980 KB |
Output is correct |
94 |
Correct |
366 ms |
7964 KB |
Output is correct |
95 |
Correct |
378 ms |
7844 KB |
Output is correct |
96 |
Correct |
469 ms |
18808 KB |
Output is correct |
97 |
Correct |
436 ms |
18732 KB |
Output is correct |
98 |
Correct |
428 ms |
13340 KB |
Output is correct |
99 |
Correct |
500 ms |
18992 KB |
Output is correct |
100 |
Correct |
330 ms |
18992 KB |
Output is correct |