#include<bits/stdc++.h>
using namespace std;
long long check(long long mid){
for(long long i=2;i*i<=mid;i++){
if(mid%i==0){
return 0;
}
}
return 1;
}
long long fiav(long long mid){
while(check(mid)){
mid++;
}
return mid;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long mod=fiav(rng()%1000000+999999000),base=fiav(rng()%100+5);
const long long maxn=200000+10;
vector<string>alls;
set<long long>allh;
long long n,q,mp[maxn],bh[maxn];
void aval(){
mp[0]=1;
bh[0]=1;
for(long long i=1;i<maxn;i++){
mp[i]=1ll*mp[i-1]*base%mod;
bh[i]=bh[i-1]+mp[i];
bh[i]%=mod;
}
}
long long geth(string s){
long long ret=0;
for(long long i=0;i<n;i++){
ret+=mp[i]*(s[i]-'a'+1)%mod;
ret%=mod;
}
return ret;
}
string gets(string a,string b){
string ret;
ret.resize(n);
for(long long i=0;i<n;i++){
if(a[i]==b[i]){
ret[i]=a[i];
}
else{
ret[i]='a'^'b'^'c'^a[i]^b[i];
}
}
return ret;
}
void tagh(string &s){
for(long long i=0;i<n;i++){
if(s[i]=='J'){
s[i]='a';
}
else if(s[i]=='O'){
s[i]='b';
}
else{
s[i]='c';
}
}
}
long long upd(){
vector<string>fake;
long long f=0;
for(long long i=0;i<(long long)alls.size();i++){
for(long long j=i+1;j<(long long)alls.size();j++){
string s=gets(alls[i],alls[j]);
long long sh=geth(s);
if((long long)allh.count(sh)==0){
f=1;
allh.insert(sh);
fake.push_back(s);
//cout<<"wtf: "<<sh<<" "<<s<<endl;
}
}
}
for(auto x:fake){
alls.push_back(x);
}
return f;
}
string now;
long long hnow;
set<pair<long long,pair<long long,char>>>allind;
void ins(long long l,long long r,char c){
hnow+=bh[r-l]*mp[l]*(c-'a'+1)%mod;
hnow%=mod;
allind.insert(make_pair(l,make_pair(r,c)));
}
void erase(long long l,long long r,char c){
hnow+=mod+mod-(bh[r-l]*mp[l]*(c-'a'+1)%mod);
hnow%=mod;
allind.erase(make_pair(l,make_pair(r,c)));
}
void updq(long long l,long long r,char c){
while((long long)allind.size()>0&&(*allind.rbegin()).first>=l){
auto x=*allind.lower_bound(make_pair(l,make_pair(0,0)));
if(x.first<=r&&x.second.first<=r){
erase(x.first,x.second.first,x.second.second);
continue;
}
if(x.first<=r){
erase(x.first,x.second.first,x.second.second);
ins(r+1,x.second.first,x.second.second);
continue;
}
break;
}
if((long long)allind.size()>0&&(*allind.begin()).first<l){
auto y=allind.lower_bound(make_pair(l,make_pair(0,0)));
y--;
auto x=*y;
if(x.second.first>r){
erase(x.first,x.second.first,x.second.second);
ins(x.first,l-1,x.second.second);
ins(r+1,x.second.first,x.second.second);
}
else if(x.second.first>=l){
erase(x.first,x.second.first,x.second.second);
ins(x.first,l-1,x.second.second);
}
}
ins(l,r,c);
}
void khor(){
//cout<<hnow<<endl;
if(allh.count(hnow)==1){
cout<<"Yes\n";
}
else{
cout<<"No\n";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
//cout.tie(0);
aval();
cin>>n;
alls.resize(3);
cin>>alls[0]>>alls[1]>>alls[2];
tagh(alls[0]);
tagh(alls[1]);
tagh(alls[2]);
while(upd()){
//hehecalackhordy
}
cin>>q;
cin>>now;
tagh(now);
//cout<<"tof: "<<now<<endl;
for(long long i=0;i<n;i++){
ins(i,i,now[i]);
}
khor();
for(long long i=0;i<q;i++){
long long l,r;
char c;
cin>>l>>r>>c;
l--;
r--;
if(c=='J'){
c='a';
}
else if(c=='O'){
c='b';
}
else{
c='c';
}
updq(l,r,c);
khor();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
4968 KB |
Output is correct |
2 |
Correct |
104 ms |
5052 KB |
Output is correct |
3 |
Correct |
72 ms |
5032 KB |
Output is correct |
4 |
Correct |
103 ms |
4944 KB |
Output is correct |
5 |
Correct |
102 ms |
5004 KB |
Output is correct |
6 |
Correct |
110 ms |
5436 KB |
Output is correct |
7 |
Correct |
102 ms |
5204 KB |
Output is correct |
8 |
Correct |
108 ms |
5096 KB |
Output is correct |
9 |
Correct |
119 ms |
5064 KB |
Output is correct |
10 |
Correct |
109 ms |
4976 KB |
Output is correct |
11 |
Correct |
110 ms |
5200 KB |
Output is correct |
12 |
Correct |
108 ms |
5132 KB |
Output is correct |
13 |
Correct |
111 ms |
5148 KB |
Output is correct |
14 |
Correct |
106 ms |
5200 KB |
Output is correct |
15 |
Correct |
111 ms |
5184 KB |
Output is correct |
16 |
Correct |
107 ms |
5068 KB |
Output is correct |
17 |
Correct |
117 ms |
5012 KB |
Output is correct |
18 |
Correct |
64 ms |
5200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
4968 KB |
Output is correct |
2 |
Correct |
104 ms |
5052 KB |
Output is correct |
3 |
Correct |
72 ms |
5032 KB |
Output is correct |
4 |
Correct |
103 ms |
4944 KB |
Output is correct |
5 |
Correct |
102 ms |
5004 KB |
Output is correct |
6 |
Correct |
110 ms |
5436 KB |
Output is correct |
7 |
Correct |
102 ms |
5204 KB |
Output is correct |
8 |
Correct |
108 ms |
5096 KB |
Output is correct |
9 |
Correct |
119 ms |
5064 KB |
Output is correct |
10 |
Correct |
109 ms |
4976 KB |
Output is correct |
11 |
Correct |
110 ms |
5200 KB |
Output is correct |
12 |
Correct |
108 ms |
5132 KB |
Output is correct |
13 |
Correct |
111 ms |
5148 KB |
Output is correct |
14 |
Correct |
106 ms |
5200 KB |
Output is correct |
15 |
Correct |
111 ms |
5184 KB |
Output is correct |
16 |
Correct |
107 ms |
5068 KB |
Output is correct |
17 |
Correct |
117 ms |
5012 KB |
Output is correct |
18 |
Correct |
64 ms |
5200 KB |
Output is correct |
19 |
Correct |
244 ms |
19508 KB |
Output is correct |
20 |
Correct |
197 ms |
19684 KB |
Output is correct |
21 |
Correct |
318 ms |
18824 KB |
Output is correct |
22 |
Correct |
295 ms |
17472 KB |
Output is correct |
23 |
Correct |
168 ms |
6228 KB |
Output is correct |
24 |
Correct |
174 ms |
6224 KB |
Output is correct |
25 |
Correct |
315 ms |
19724 KB |
Output is correct |
26 |
Correct |
303 ms |
19612 KB |
Output is correct |
27 |
Correct |
257 ms |
19704 KB |
Output is correct |
28 |
Correct |
270 ms |
19744 KB |
Output is correct |
29 |
Correct |
265 ms |
19252 KB |
Output is correct |
30 |
Correct |
160 ms |
6368 KB |
Output is correct |
31 |
Correct |
261 ms |
19656 KB |
Output is correct |
32 |
Correct |
260 ms |
18436 KB |
Output is correct |
33 |
Correct |
196 ms |
6360 KB |
Output is correct |
34 |
Correct |
273 ms |
19744 KB |
Output is correct |
35 |
Correct |
300 ms |
15976 KB |
Output is correct |
36 |
Correct |
177 ms |
6328 KB |
Output is correct |
37 |
Correct |
174 ms |
6480 KB |
Output is correct |
38 |
Correct |
189 ms |
19680 KB |
Output is correct |
39 |
Correct |
246 ms |
19600 KB |
Output is correct |
40 |
Correct |
334 ms |
14632 KB |
Output is correct |
41 |
Correct |
260 ms |
19708 KB |
Output is correct |
42 |
Correct |
124 ms |
19664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
4968 KB |
Output is correct |
2 |
Correct |
104 ms |
5052 KB |
Output is correct |
3 |
Correct |
72 ms |
5032 KB |
Output is correct |
4 |
Correct |
103 ms |
4944 KB |
Output is correct |
5 |
Correct |
102 ms |
5004 KB |
Output is correct |
6 |
Correct |
110 ms |
5436 KB |
Output is correct |
7 |
Correct |
102 ms |
5204 KB |
Output is correct |
8 |
Correct |
108 ms |
5096 KB |
Output is correct |
9 |
Correct |
119 ms |
5064 KB |
Output is correct |
10 |
Correct |
109 ms |
4976 KB |
Output is correct |
11 |
Correct |
110 ms |
5200 KB |
Output is correct |
12 |
Correct |
108 ms |
5132 KB |
Output is correct |
13 |
Correct |
111 ms |
5148 KB |
Output is correct |
14 |
Correct |
106 ms |
5200 KB |
Output is correct |
15 |
Correct |
111 ms |
5184 KB |
Output is correct |
16 |
Correct |
107 ms |
5068 KB |
Output is correct |
17 |
Correct |
117 ms |
5012 KB |
Output is correct |
18 |
Correct |
64 ms |
5200 KB |
Output is correct |
19 |
Correct |
108 ms |
5116 KB |
Output is correct |
20 |
Correct |
75 ms |
5204 KB |
Output is correct |
21 |
Correct |
108 ms |
5204 KB |
Output is correct |
22 |
Correct |
95 ms |
4948 KB |
Output is correct |
23 |
Correct |
111 ms |
5140 KB |
Output is correct |
24 |
Correct |
105 ms |
4948 KB |
Output is correct |
25 |
Correct |
109 ms |
5128 KB |
Output is correct |
26 |
Correct |
100 ms |
4948 KB |
Output is correct |
27 |
Correct |
108 ms |
5112 KB |
Output is correct |
28 |
Correct |
104 ms |
4984 KB |
Output is correct |
29 |
Correct |
116 ms |
5192 KB |
Output is correct |
30 |
Correct |
98 ms |
4944 KB |
Output is correct |
31 |
Correct |
113 ms |
5172 KB |
Output is correct |
32 |
Correct |
108 ms |
4988 KB |
Output is correct |
33 |
Correct |
115 ms |
5348 KB |
Output is correct |
34 |
Correct |
105 ms |
4948 KB |
Output is correct |
35 |
Correct |
109 ms |
5204 KB |
Output is correct |
36 |
Correct |
112 ms |
5032 KB |
Output is correct |
37 |
Correct |
117 ms |
5252 KB |
Output is correct |
38 |
Correct |
113 ms |
5024 KB |
Output is correct |
39 |
Correct |
109 ms |
5036 KB |
Output is correct |
40 |
Correct |
114 ms |
5052 KB |
Output is correct |
41 |
Correct |
114 ms |
5096 KB |
Output is correct |
42 |
Correct |
119 ms |
5196 KB |
Output is correct |
43 |
Correct |
107 ms |
5200 KB |
Output is correct |
44 |
Correct |
113 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
4968 KB |
Output is correct |
2 |
Correct |
104 ms |
5052 KB |
Output is correct |
3 |
Correct |
72 ms |
5032 KB |
Output is correct |
4 |
Correct |
103 ms |
4944 KB |
Output is correct |
5 |
Correct |
102 ms |
5004 KB |
Output is correct |
6 |
Correct |
110 ms |
5436 KB |
Output is correct |
7 |
Correct |
102 ms |
5204 KB |
Output is correct |
8 |
Correct |
108 ms |
5096 KB |
Output is correct |
9 |
Correct |
119 ms |
5064 KB |
Output is correct |
10 |
Correct |
109 ms |
4976 KB |
Output is correct |
11 |
Correct |
110 ms |
5200 KB |
Output is correct |
12 |
Correct |
108 ms |
5132 KB |
Output is correct |
13 |
Correct |
111 ms |
5148 KB |
Output is correct |
14 |
Correct |
106 ms |
5200 KB |
Output is correct |
15 |
Correct |
111 ms |
5184 KB |
Output is correct |
16 |
Correct |
107 ms |
5068 KB |
Output is correct |
17 |
Correct |
117 ms |
5012 KB |
Output is correct |
18 |
Correct |
64 ms |
5200 KB |
Output is correct |
19 |
Correct |
244 ms |
19508 KB |
Output is correct |
20 |
Correct |
197 ms |
19684 KB |
Output is correct |
21 |
Correct |
318 ms |
18824 KB |
Output is correct |
22 |
Correct |
295 ms |
17472 KB |
Output is correct |
23 |
Correct |
168 ms |
6228 KB |
Output is correct |
24 |
Correct |
174 ms |
6224 KB |
Output is correct |
25 |
Correct |
315 ms |
19724 KB |
Output is correct |
26 |
Correct |
303 ms |
19612 KB |
Output is correct |
27 |
Correct |
257 ms |
19704 KB |
Output is correct |
28 |
Correct |
270 ms |
19744 KB |
Output is correct |
29 |
Correct |
265 ms |
19252 KB |
Output is correct |
30 |
Correct |
160 ms |
6368 KB |
Output is correct |
31 |
Correct |
261 ms |
19656 KB |
Output is correct |
32 |
Correct |
260 ms |
18436 KB |
Output is correct |
33 |
Correct |
196 ms |
6360 KB |
Output is correct |
34 |
Correct |
273 ms |
19744 KB |
Output is correct |
35 |
Correct |
300 ms |
15976 KB |
Output is correct |
36 |
Correct |
177 ms |
6328 KB |
Output is correct |
37 |
Correct |
174 ms |
6480 KB |
Output is correct |
38 |
Correct |
189 ms |
19680 KB |
Output is correct |
39 |
Correct |
246 ms |
19600 KB |
Output is correct |
40 |
Correct |
334 ms |
14632 KB |
Output is correct |
41 |
Correct |
260 ms |
19708 KB |
Output is correct |
42 |
Correct |
124 ms |
19664 KB |
Output is correct |
43 |
Correct |
108 ms |
5116 KB |
Output is correct |
44 |
Correct |
75 ms |
5204 KB |
Output is correct |
45 |
Correct |
108 ms |
5204 KB |
Output is correct |
46 |
Correct |
95 ms |
4948 KB |
Output is correct |
47 |
Correct |
111 ms |
5140 KB |
Output is correct |
48 |
Correct |
105 ms |
4948 KB |
Output is correct |
49 |
Correct |
109 ms |
5128 KB |
Output is correct |
50 |
Correct |
100 ms |
4948 KB |
Output is correct |
51 |
Correct |
108 ms |
5112 KB |
Output is correct |
52 |
Correct |
104 ms |
4984 KB |
Output is correct |
53 |
Correct |
116 ms |
5192 KB |
Output is correct |
54 |
Correct |
98 ms |
4944 KB |
Output is correct |
55 |
Correct |
113 ms |
5172 KB |
Output is correct |
56 |
Correct |
108 ms |
4988 KB |
Output is correct |
57 |
Correct |
115 ms |
5348 KB |
Output is correct |
58 |
Correct |
105 ms |
4948 KB |
Output is correct |
59 |
Correct |
109 ms |
5204 KB |
Output is correct |
60 |
Correct |
112 ms |
5032 KB |
Output is correct |
61 |
Correct |
117 ms |
5252 KB |
Output is correct |
62 |
Correct |
113 ms |
5024 KB |
Output is correct |
63 |
Correct |
109 ms |
5036 KB |
Output is correct |
64 |
Correct |
114 ms |
5052 KB |
Output is correct |
65 |
Correct |
114 ms |
5096 KB |
Output is correct |
66 |
Correct |
119 ms |
5196 KB |
Output is correct |
67 |
Correct |
107 ms |
5200 KB |
Output is correct |
68 |
Correct |
113 ms |
5196 KB |
Output is correct |
69 |
Correct |
330 ms |
18612 KB |
Output is correct |
70 |
Correct |
359 ms |
21256 KB |
Output is correct |
71 |
Correct |
180 ms |
6416 KB |
Output is correct |
72 |
Correct |
183 ms |
6368 KB |
Output is correct |
73 |
Correct |
180 ms |
6264 KB |
Output is correct |
74 |
Correct |
298 ms |
17660 KB |
Output is correct |
75 |
Correct |
171 ms |
6224 KB |
Output is correct |
76 |
Correct |
318 ms |
20076 KB |
Output is correct |
77 |
Correct |
285 ms |
17768 KB |
Output is correct |
78 |
Correct |
181 ms |
6444 KB |
Output is correct |
79 |
Correct |
178 ms |
6284 KB |
Output is correct |
80 |
Correct |
354 ms |
16980 KB |
Output is correct |
81 |
Correct |
178 ms |
6228 KB |
Output is correct |
82 |
Correct |
482 ms |
21164 KB |
Output is correct |
83 |
Correct |
440 ms |
20280 KB |
Output is correct |
84 |
Incorrect |
191 ms |
6640 KB |
Output isn't correct |
85 |
Halted |
0 ms |
0 KB |
- |