#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N,Q;
set<string> k;
string a,b,c;
string t;
vector<vector<int> > h;
const int dim=50;
const int p=257,mod=1e9+9;
vector<int> pot;
vector<int> tt;
map<char,int> val;
vector<char> qq(1000010,'x');
int hasha(string q){
int l=0;
for(auto k:q)l=(l*p+k)%mod;
for(int i=q.size();i<dim;i++)l=l*p%mod;
return l;
}
void solve(){
for(auto v:h){
bool ok=1;
for(int i=0;i<v.size();i++)if(v[i]!=tt[i])ok=0;
if(ok){
cout<<"Yes\n";
return;
}
}
cout<<"No\n";
}
string cross(string x,string y){
string ans="";
vector<char> s={'I','J','O'};
for(int i=0;i<x.size();i++){
if(x[i]==y[i])ans+=x[i];
else{
for(auto h:s)if(x[i]!=h && y[i]!=h)ans+=h;
}
}
return ans;
}
void calc(){
while(1){
bool ok=0;
for(auto x:k){
for(auto y:k){
string h=cross(x,y);
if(k.count(h))continue;
ok=1;
k.insert(h);
}
}
if(!ok)break;
}
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>N>>a>>b>>c>>Q>>t;
k.insert(a);k.insert(b);k.insert(c);
calc();
assert(k.size()<10);
pot={1};
for(int i=0;i<300010;i++)pot.pb(pot.back()*p%mod);
val['I']=hasha(string(dim,'I'));
val['J']=hasha(string(dim,'J'));
val['O']=hasha(string(dim,'O'));
for(auto y:k){
h.pb(vector<int> ());
for(int i=0;i*dim<N;i++){
string cur="";
for(int j=dim*i;j<min(N,dim*(i+1));j++){
cur+=y[j];
}
h.back().pb(hasha(cur));
//cout<<"iniziali: "<<h.back().back()<<endl;
}
}
for(int i=0;i*dim<N;i++){
string cur="";
for(int j=dim*i;j<min(N,dim*(i+1));j++){
cur+=t[j];
}
tt.pb(hasha(cur));
}
//cout<<tt[0]<<" "<<hasha(t)<<endl;
solve();
for(int i=0;i<Q;i++){
int x,y;
char z;
cin>>x>>y>>z;
x--;y--;
int pos=x-x%dim;
for(int j=pos;j<min(N,pos+dim);j++){
int pp=j/dim;
if(qq[pp]!='x')t[j]=qq[pp];
tt[pp]-=t[j]*pot[dim-j%dim-1];
if(j>=x && j<=y)t[j]=z;
tt[pp]+=t[j]*pot[dim-j%dim-1];
tt[pp]=(tt[pp]%mod+mod)%mod;
}
qq[pos/dim]='x';
x=x-x%dim+dim;
pos=y-y%dim;
for(int j=pos;j<min(N,pos+dim);j++){
int pp=j/dim;
if(qq[pp]!='x')t[j]=qq[pp];
tt[pp]-=t[j]*pot[dim-j%dim-1];
if(j>=x && j<=y)t[j]=z;
tt[pp]+=t[j]*pot[dim-j%dim-1];
tt[pp]=(tt[pp]%mod+mod)%mod;
}
y=y-y%dim;
qq[pos/dim]='x';
for(int j=x;j<y;j+=dim){
int pp=j/dim;
tt[pp]=val[z];
qq[pp]=z;
}
//cout<<tt[0]<<" "<<hasha(t)<<endl;
solve();
}
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:31:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<v.size();i++)if(v[i]!=tt[i])ok=0;
| ~^~~~~~~~~
Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i=0;i<x.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
5444 KB |
Output is correct |
2 |
Correct |
307 ms |
5444 KB |
Output is correct |
3 |
Correct |
334 ms |
5496 KB |
Output is correct |
4 |
Correct |
289 ms |
5444 KB |
Output is correct |
5 |
Correct |
279 ms |
5444 KB |
Output is correct |
6 |
Correct |
283 ms |
5444 KB |
Output is correct |
7 |
Correct |
261 ms |
5588 KB |
Output is correct |
8 |
Correct |
305 ms |
5444 KB |
Output is correct |
9 |
Correct |
303 ms |
5444 KB |
Output is correct |
10 |
Correct |
307 ms |
5444 KB |
Output is correct |
11 |
Correct |
304 ms |
5444 KB |
Output is correct |
12 |
Correct |
320 ms |
5444 KB |
Output is correct |
13 |
Correct |
322 ms |
5444 KB |
Output is correct |
14 |
Correct |
304 ms |
5572 KB |
Output is correct |
15 |
Correct |
303 ms |
5444 KB |
Output is correct |
16 |
Correct |
303 ms |
5500 KB |
Output is correct |
17 |
Correct |
307 ms |
5444 KB |
Output is correct |
18 |
Correct |
345 ms |
5544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
5444 KB |
Output is correct |
2 |
Correct |
307 ms |
5444 KB |
Output is correct |
3 |
Correct |
334 ms |
5496 KB |
Output is correct |
4 |
Correct |
289 ms |
5444 KB |
Output is correct |
5 |
Correct |
279 ms |
5444 KB |
Output is correct |
6 |
Correct |
283 ms |
5444 KB |
Output is correct |
7 |
Correct |
261 ms |
5588 KB |
Output is correct |
8 |
Correct |
305 ms |
5444 KB |
Output is correct |
9 |
Correct |
303 ms |
5444 KB |
Output is correct |
10 |
Correct |
307 ms |
5444 KB |
Output is correct |
11 |
Correct |
304 ms |
5444 KB |
Output is correct |
12 |
Correct |
320 ms |
5444 KB |
Output is correct |
13 |
Correct |
322 ms |
5444 KB |
Output is correct |
14 |
Correct |
304 ms |
5572 KB |
Output is correct |
15 |
Correct |
303 ms |
5444 KB |
Output is correct |
16 |
Correct |
303 ms |
5500 KB |
Output is correct |
17 |
Correct |
307 ms |
5444 KB |
Output is correct |
18 |
Correct |
345 ms |
5544 KB |
Output is correct |
19 |
Correct |
1755 ms |
6608 KB |
Output is correct |
20 |
Correct |
5682 ms |
6608 KB |
Output is correct |
21 |
Correct |
957 ms |
6588 KB |
Output is correct |
22 |
Correct |
897 ms |
6512 KB |
Output is correct |
23 |
Correct |
370 ms |
5564 KB |
Output is correct |
24 |
Correct |
369 ms |
5564 KB |
Output is correct |
25 |
Correct |
1158 ms |
6652 KB |
Output is correct |
26 |
Correct |
1055 ms |
6608 KB |
Output is correct |
27 |
Correct |
1212 ms |
6608 KB |
Output is correct |
28 |
Correct |
1195 ms |
6608 KB |
Output is correct |
29 |
Correct |
1205 ms |
6624 KB |
Output is correct |
30 |
Correct |
393 ms |
5564 KB |
Output is correct |
31 |
Correct |
1205 ms |
6608 KB |
Output is correct |
32 |
Correct |
1086 ms |
6556 KB |
Output is correct |
33 |
Correct |
373 ms |
5564 KB |
Output is correct |
34 |
Correct |
1175 ms |
6608 KB |
Output is correct |
35 |
Correct |
809 ms |
6432 KB |
Output is correct |
36 |
Correct |
365 ms |
5692 KB |
Output is correct |
37 |
Correct |
369 ms |
5564 KB |
Output is correct |
38 |
Correct |
5770 ms |
6608 KB |
Output is correct |
39 |
Correct |
1064 ms |
6608 KB |
Output is correct |
40 |
Correct |
815 ms |
6256 KB |
Output is correct |
41 |
Correct |
2814 ms |
6608 KB |
Output is correct |
42 |
Correct |
6204 ms |
6608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
5444 KB |
Output is correct |
2 |
Correct |
307 ms |
5444 KB |
Output is correct |
3 |
Correct |
334 ms |
5496 KB |
Output is correct |
4 |
Correct |
289 ms |
5444 KB |
Output is correct |
5 |
Correct |
279 ms |
5444 KB |
Output is correct |
6 |
Correct |
283 ms |
5444 KB |
Output is correct |
7 |
Correct |
261 ms |
5588 KB |
Output is correct |
8 |
Correct |
305 ms |
5444 KB |
Output is correct |
9 |
Correct |
303 ms |
5444 KB |
Output is correct |
10 |
Correct |
307 ms |
5444 KB |
Output is correct |
11 |
Correct |
304 ms |
5444 KB |
Output is correct |
12 |
Correct |
320 ms |
5444 KB |
Output is correct |
13 |
Correct |
322 ms |
5444 KB |
Output is correct |
14 |
Correct |
304 ms |
5572 KB |
Output is correct |
15 |
Correct |
303 ms |
5444 KB |
Output is correct |
16 |
Correct |
303 ms |
5500 KB |
Output is correct |
17 |
Correct |
307 ms |
5444 KB |
Output is correct |
18 |
Correct |
345 ms |
5544 KB |
Output is correct |
19 |
Correct |
343 ms |
5440 KB |
Output is correct |
20 |
Correct |
402 ms |
5440 KB |
Output is correct |
21 |
Correct |
321 ms |
5444 KB |
Output is correct |
22 |
Correct |
255 ms |
5444 KB |
Output is correct |
23 |
Correct |
318 ms |
5444 KB |
Output is correct |
24 |
Correct |
290 ms |
5444 KB |
Output is correct |
25 |
Correct |
321 ms |
5444 KB |
Output is correct |
26 |
Correct |
269 ms |
5492 KB |
Output is correct |
27 |
Correct |
322 ms |
5444 KB |
Output is correct |
28 |
Correct |
284 ms |
5500 KB |
Output is correct |
29 |
Correct |
330 ms |
5444 KB |
Output is correct |
30 |
Correct |
286 ms |
5524 KB |
Output is correct |
31 |
Correct |
360 ms |
5568 KB |
Output is correct |
32 |
Correct |
339 ms |
5568 KB |
Output is correct |
33 |
Correct |
360 ms |
5440 KB |
Output is correct |
34 |
Correct |
299 ms |
5440 KB |
Output is correct |
35 |
Correct |
361 ms |
5440 KB |
Output is correct |
36 |
Correct |
367 ms |
5440 KB |
Output is correct |
37 |
Correct |
359 ms |
5440 KB |
Output is correct |
38 |
Correct |
358 ms |
5440 KB |
Output is correct |
39 |
Correct |
401 ms |
5440 KB |
Output is correct |
40 |
Correct |
358 ms |
5568 KB |
Output is correct |
41 |
Correct |
392 ms |
5440 KB |
Output is correct |
42 |
Correct |
353 ms |
5440 KB |
Output is correct |
43 |
Correct |
360 ms |
5496 KB |
Output is correct |
44 |
Correct |
365 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
5444 KB |
Output is correct |
2 |
Correct |
307 ms |
5444 KB |
Output is correct |
3 |
Correct |
334 ms |
5496 KB |
Output is correct |
4 |
Correct |
289 ms |
5444 KB |
Output is correct |
5 |
Correct |
279 ms |
5444 KB |
Output is correct |
6 |
Correct |
283 ms |
5444 KB |
Output is correct |
7 |
Correct |
261 ms |
5588 KB |
Output is correct |
8 |
Correct |
305 ms |
5444 KB |
Output is correct |
9 |
Correct |
303 ms |
5444 KB |
Output is correct |
10 |
Correct |
307 ms |
5444 KB |
Output is correct |
11 |
Correct |
304 ms |
5444 KB |
Output is correct |
12 |
Correct |
320 ms |
5444 KB |
Output is correct |
13 |
Correct |
322 ms |
5444 KB |
Output is correct |
14 |
Correct |
304 ms |
5572 KB |
Output is correct |
15 |
Correct |
303 ms |
5444 KB |
Output is correct |
16 |
Correct |
303 ms |
5500 KB |
Output is correct |
17 |
Correct |
307 ms |
5444 KB |
Output is correct |
18 |
Correct |
345 ms |
5544 KB |
Output is correct |
19 |
Correct |
1755 ms |
6608 KB |
Output is correct |
20 |
Correct |
5682 ms |
6608 KB |
Output is correct |
21 |
Correct |
957 ms |
6588 KB |
Output is correct |
22 |
Correct |
897 ms |
6512 KB |
Output is correct |
23 |
Correct |
370 ms |
5564 KB |
Output is correct |
24 |
Correct |
369 ms |
5564 KB |
Output is correct |
25 |
Correct |
1158 ms |
6652 KB |
Output is correct |
26 |
Correct |
1055 ms |
6608 KB |
Output is correct |
27 |
Correct |
1212 ms |
6608 KB |
Output is correct |
28 |
Correct |
1195 ms |
6608 KB |
Output is correct |
29 |
Correct |
1205 ms |
6624 KB |
Output is correct |
30 |
Correct |
393 ms |
5564 KB |
Output is correct |
31 |
Correct |
1205 ms |
6608 KB |
Output is correct |
32 |
Correct |
1086 ms |
6556 KB |
Output is correct |
33 |
Correct |
373 ms |
5564 KB |
Output is correct |
34 |
Correct |
1175 ms |
6608 KB |
Output is correct |
35 |
Correct |
809 ms |
6432 KB |
Output is correct |
36 |
Correct |
365 ms |
5692 KB |
Output is correct |
37 |
Correct |
369 ms |
5564 KB |
Output is correct |
38 |
Correct |
5770 ms |
6608 KB |
Output is correct |
39 |
Correct |
1064 ms |
6608 KB |
Output is correct |
40 |
Correct |
815 ms |
6256 KB |
Output is correct |
41 |
Correct |
2814 ms |
6608 KB |
Output is correct |
42 |
Correct |
6204 ms |
6608 KB |
Output is correct |
43 |
Correct |
343 ms |
5440 KB |
Output is correct |
44 |
Correct |
402 ms |
5440 KB |
Output is correct |
45 |
Correct |
321 ms |
5444 KB |
Output is correct |
46 |
Correct |
255 ms |
5444 KB |
Output is correct |
47 |
Correct |
318 ms |
5444 KB |
Output is correct |
48 |
Correct |
290 ms |
5444 KB |
Output is correct |
49 |
Correct |
321 ms |
5444 KB |
Output is correct |
50 |
Correct |
269 ms |
5492 KB |
Output is correct |
51 |
Correct |
322 ms |
5444 KB |
Output is correct |
52 |
Correct |
284 ms |
5500 KB |
Output is correct |
53 |
Correct |
330 ms |
5444 KB |
Output is correct |
54 |
Correct |
286 ms |
5524 KB |
Output is correct |
55 |
Correct |
360 ms |
5568 KB |
Output is correct |
56 |
Correct |
339 ms |
5568 KB |
Output is correct |
57 |
Correct |
360 ms |
5440 KB |
Output is correct |
58 |
Correct |
299 ms |
5440 KB |
Output is correct |
59 |
Correct |
361 ms |
5440 KB |
Output is correct |
60 |
Correct |
367 ms |
5440 KB |
Output is correct |
61 |
Correct |
359 ms |
5440 KB |
Output is correct |
62 |
Correct |
358 ms |
5440 KB |
Output is correct |
63 |
Correct |
401 ms |
5440 KB |
Output is correct |
64 |
Correct |
358 ms |
5568 KB |
Output is correct |
65 |
Correct |
392 ms |
5440 KB |
Output is correct |
66 |
Correct |
353 ms |
5440 KB |
Output is correct |
67 |
Correct |
360 ms |
5496 KB |
Output is correct |
68 |
Correct |
365 ms |
5452 KB |
Output is correct |
69 |
Correct |
6466 ms |
8236 KB |
Output is correct |
70 |
Execution timed out |
7040 ms |
8972 KB |
Time limit exceeded |
71 |
Halted |
0 ms |
0 KB |
- |