Submission #916266

# Submission time Handle Problem Language Result Execution time Memory
916266 2024-01-25T14:54:26 Z amirhoseinfar1385 Crossing (JOI21_crossing) C++17
100 / 100
489 ms 21584 KB
#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 100 ms 4092 KB Output is correct
2 Correct 105 ms 4144 KB Output is correct
3 Correct 73 ms 4180 KB Output is correct
4 Correct 104 ms 4056 KB Output is correct
5 Correct 102 ms 3916 KB Output is correct
6 Correct 103 ms 4084 KB Output is correct
7 Correct 105 ms 4144 KB Output is correct
8 Correct 106 ms 4176 KB Output is correct
9 Correct 111 ms 4036 KB Output is correct
10 Correct 106 ms 4108 KB Output is correct
11 Correct 116 ms 4184 KB Output is correct
12 Correct 108 ms 4188 KB Output is correct
13 Correct 109 ms 4180 KB Output is correct
14 Correct 107 ms 4152 KB Output is correct
15 Correct 110 ms 4180 KB Output is correct
16 Correct 106 ms 4144 KB Output is correct
17 Correct 119 ms 4024 KB Output is correct
18 Correct 64 ms 4024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 4092 KB Output is correct
2 Correct 105 ms 4144 KB Output is correct
3 Correct 73 ms 4180 KB Output is correct
4 Correct 104 ms 4056 KB Output is correct
5 Correct 102 ms 3916 KB Output is correct
6 Correct 103 ms 4084 KB Output is correct
7 Correct 105 ms 4144 KB Output is correct
8 Correct 106 ms 4176 KB Output is correct
9 Correct 111 ms 4036 KB Output is correct
10 Correct 106 ms 4108 KB Output is correct
11 Correct 116 ms 4184 KB Output is correct
12 Correct 108 ms 4188 KB Output is correct
13 Correct 109 ms 4180 KB Output is correct
14 Correct 107 ms 4152 KB Output is correct
15 Correct 110 ms 4180 KB Output is correct
16 Correct 106 ms 4144 KB Output is correct
17 Correct 119 ms 4024 KB Output is correct
18 Correct 64 ms 4024 KB Output is correct
19 Correct 249 ms 17500 KB Output is correct
20 Correct 196 ms 17636 KB Output is correct
21 Correct 307 ms 16860 KB Output is correct
22 Correct 267 ms 15752 KB Output is correct
23 Correct 171 ms 4692 KB Output is correct
24 Correct 176 ms 5116 KB Output is correct
25 Correct 300 ms 17680 KB Output is correct
26 Correct 317 ms 17948 KB Output is correct
27 Correct 245 ms 17520 KB Output is correct
28 Correct 279 ms 17688 KB Output is correct
29 Correct 243 ms 17296 KB Output is correct
30 Correct 154 ms 4692 KB Output is correct
31 Correct 259 ms 17788 KB Output is correct
32 Correct 254 ms 16404 KB Output is correct
33 Correct 200 ms 4692 KB Output is correct
34 Correct 280 ms 17496 KB Output is correct
35 Correct 357 ms 13992 KB Output is correct
36 Correct 189 ms 4688 KB Output is correct
37 Correct 185 ms 4824 KB Output is correct
38 Correct 156 ms 17608 KB Output is correct
39 Correct 229 ms 17640 KB Output is correct
40 Correct 289 ms 12828 KB Output is correct
41 Correct 207 ms 17892 KB Output is correct
42 Correct 117 ms 17704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 4092 KB Output is correct
2 Correct 105 ms 4144 KB Output is correct
3 Correct 73 ms 4180 KB Output is correct
4 Correct 104 ms 4056 KB Output is correct
5 Correct 102 ms 3916 KB Output is correct
6 Correct 103 ms 4084 KB Output is correct
7 Correct 105 ms 4144 KB Output is correct
8 Correct 106 ms 4176 KB Output is correct
9 Correct 111 ms 4036 KB Output is correct
10 Correct 106 ms 4108 KB Output is correct
11 Correct 116 ms 4184 KB Output is correct
12 Correct 108 ms 4188 KB Output is correct
13 Correct 109 ms 4180 KB Output is correct
14 Correct 107 ms 4152 KB Output is correct
15 Correct 110 ms 4180 KB Output is correct
16 Correct 106 ms 4144 KB Output is correct
17 Correct 119 ms 4024 KB Output is correct
18 Correct 64 ms 4024 KB Output is correct
19 Correct 102 ms 4136 KB Output is correct
20 Correct 79 ms 4032 KB Output is correct
21 Correct 110 ms 4176 KB Output is correct
22 Correct 94 ms 3916 KB Output is correct
23 Correct 119 ms 4008 KB Output is correct
24 Correct 109 ms 4164 KB Output is correct
25 Correct 116 ms 3940 KB Output is correct
26 Correct 102 ms 4240 KB Output is correct
27 Correct 117 ms 3980 KB Output is correct
28 Correct 101 ms 3968 KB Output is correct
29 Correct 110 ms 3988 KB Output is correct
30 Correct 96 ms 3924 KB Output is correct
31 Correct 110 ms 4176 KB Output is correct
32 Correct 107 ms 3948 KB Output is correct
33 Correct 112 ms 3960 KB Output is correct
34 Correct 105 ms 3924 KB Output is correct
35 Correct 115 ms 4052 KB Output is correct
36 Correct 131 ms 4008 KB Output is correct
37 Correct 121 ms 4236 KB Output is correct
38 Correct 128 ms 4180 KB Output is correct
39 Correct 112 ms 4168 KB Output is correct
40 Correct 111 ms 4120 KB Output is correct
41 Correct 113 ms 4652 KB Output is correct
42 Correct 126 ms 4176 KB Output is correct
43 Correct 107 ms 4176 KB Output is correct
44 Correct 111 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 4092 KB Output is correct
2 Correct 105 ms 4144 KB Output is correct
3 Correct 73 ms 4180 KB Output is correct
4 Correct 104 ms 4056 KB Output is correct
5 Correct 102 ms 3916 KB Output is correct
6 Correct 103 ms 4084 KB Output is correct
7 Correct 105 ms 4144 KB Output is correct
8 Correct 106 ms 4176 KB Output is correct
9 Correct 111 ms 4036 KB Output is correct
10 Correct 106 ms 4108 KB Output is correct
11 Correct 116 ms 4184 KB Output is correct
12 Correct 108 ms 4188 KB Output is correct
13 Correct 109 ms 4180 KB Output is correct
14 Correct 107 ms 4152 KB Output is correct
15 Correct 110 ms 4180 KB Output is correct
16 Correct 106 ms 4144 KB Output is correct
17 Correct 119 ms 4024 KB Output is correct
18 Correct 64 ms 4024 KB Output is correct
19 Correct 249 ms 17500 KB Output is correct
20 Correct 196 ms 17636 KB Output is correct
21 Correct 307 ms 16860 KB Output is correct
22 Correct 267 ms 15752 KB Output is correct
23 Correct 171 ms 4692 KB Output is correct
24 Correct 176 ms 5116 KB Output is correct
25 Correct 300 ms 17680 KB Output is correct
26 Correct 317 ms 17948 KB Output is correct
27 Correct 245 ms 17520 KB Output is correct
28 Correct 279 ms 17688 KB Output is correct
29 Correct 243 ms 17296 KB Output is correct
30 Correct 154 ms 4692 KB Output is correct
31 Correct 259 ms 17788 KB Output is correct
32 Correct 254 ms 16404 KB Output is correct
33 Correct 200 ms 4692 KB Output is correct
34 Correct 280 ms 17496 KB Output is correct
35 Correct 357 ms 13992 KB Output is correct
36 Correct 189 ms 4688 KB Output is correct
37 Correct 185 ms 4824 KB Output is correct
38 Correct 156 ms 17608 KB Output is correct
39 Correct 229 ms 17640 KB Output is correct
40 Correct 289 ms 12828 KB Output is correct
41 Correct 207 ms 17892 KB Output is correct
42 Correct 117 ms 17704 KB Output is correct
43 Correct 102 ms 4136 KB Output is correct
44 Correct 79 ms 4032 KB Output is correct
45 Correct 110 ms 4176 KB Output is correct
46 Correct 94 ms 3916 KB Output is correct
47 Correct 119 ms 4008 KB Output is correct
48 Correct 109 ms 4164 KB Output is correct
49 Correct 116 ms 3940 KB Output is correct
50 Correct 102 ms 4240 KB Output is correct
51 Correct 117 ms 3980 KB Output is correct
52 Correct 101 ms 3968 KB Output is correct
53 Correct 110 ms 3988 KB Output is correct
54 Correct 96 ms 3924 KB Output is correct
55 Correct 110 ms 4176 KB Output is correct
56 Correct 107 ms 3948 KB Output is correct
57 Correct 112 ms 3960 KB Output is correct
58 Correct 105 ms 3924 KB Output is correct
59 Correct 115 ms 4052 KB Output is correct
60 Correct 131 ms 4008 KB Output is correct
61 Correct 121 ms 4236 KB Output is correct
62 Correct 128 ms 4180 KB Output is correct
63 Correct 112 ms 4168 KB Output is correct
64 Correct 111 ms 4120 KB Output is correct
65 Correct 113 ms 4652 KB Output is correct
66 Correct 126 ms 4176 KB Output is correct
67 Correct 107 ms 4176 KB Output is correct
68 Correct 111 ms 4180 KB Output is correct
69 Correct 332 ms 16776 KB Output is correct
70 Correct 341 ms 19204 KB Output is correct
71 Correct 195 ms 4660 KB Output is correct
72 Correct 174 ms 4832 KB Output is correct
73 Correct 189 ms 4692 KB Output is correct
74 Correct 284 ms 15696 KB Output is correct
75 Correct 167 ms 4824 KB Output is correct
76 Correct 344 ms 18200 KB Output is correct
77 Correct 275 ms 15736 KB Output is correct
78 Correct 182 ms 5008 KB Output is correct
79 Correct 176 ms 4692 KB Output is correct
80 Correct 363 ms 15216 KB Output is correct
81 Correct 179 ms 4712 KB Output is correct
82 Correct 472 ms 19316 KB Output is correct
83 Correct 416 ms 18220 KB Output is correct
84 Correct 189 ms 5084 KB Output is correct
85 Correct 185 ms 6472 KB Output is correct
86 Correct 336 ms 17252 KB Output is correct
87 Correct 428 ms 21188 KB Output is correct
88 Correct 188 ms 6476 KB Output is correct
89 Correct 386 ms 19300 KB Output is correct
90 Correct 489 ms 21540 KB Output is correct
91 Correct 173 ms 6264 KB Output is correct
92 Correct 384 ms 17072 KB Output is correct
93 Correct 183 ms 6228 KB Output is correct
94 Correct 183 ms 6388 KB Output is correct
95 Correct 189 ms 6484 KB Output is correct
96 Correct 165 ms 19732 KB Output is correct
97 Correct 402 ms 21456 KB Output is correct
98 Correct 390 ms 15864 KB Output is correct
99 Correct 364 ms 21584 KB Output is correct
100 Correct 280 ms 21276 KB Output is correct