Submission #459657

# Submission time Handle Problem Language Result Execution time Memory
459657 2021-08-08T22:39:03 Z Antekb Klasika (COCI20_klasika) C++14
110 / 110
1792 ms 286864 KB
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
const int N = (1<<16), M=6e7;
int pre[5*N], post[5*N], xo[5*N];
vector<int> E[5*N];
int L[M], R[M];
int wsk;
//int root[5*N];
void dfs(int v){
	pre[v]=wsk++;
	for(int u:E[v])dfs(u);
	post[v]=wsk;
}
const int K=31;
void ins(int r, int x){
	//cout<<"+ "<<r<<" "<<x<<"\n";
	for(int i=K-1; i>=0; i--){
		if(x&(1<<i)){
			if(!L[r])L[r]=wsk++;
			r=L[r];
		}
		else{
			if(!R[r])R[r]=wsk++;
			r=R[r];
		}
	}
}
int find(int r, int x){
	//cout<<"? "<<r<<" "<<x<<"\n";
	int ans=0;
	for(int i=K-1; i>=0; i--){
		if((x&(1<<i))==0){
			if(!L[r])r=R[r];
			else r=L[r], ans+=(1<<i);
		}
		else{
			if(!R[r])r=L[r];
			else r=R[r], ans+=(1<<i);
		}
	}
	//cout<<"! "<<ans<<"\n";
	return ans;
}
int main(){
	int q;
	cin>>q;
	int n=1;
	vector<pair<int, pair<int, int> > > Q(q);
	for(int i=0; i<q; i++){
		string s;
		cin>>s;
		cin>>Q[i].nd.st>>Q[i].nd.nd;
		if(s!="Add"){
			Q[i].st=1;
		}
		else{
			E[Q[i].nd.st].push_back(++n);
			xo[n]=xo[Q[i].nd.st]^Q[i].nd.nd;
			//cout<<n<<" "<<Q[i].nd.st<<""
			Q[i].nd.st=n;
		}
	}
	dfs(1);
	wsk=5*N;
	//for(int i=1; i<5*N; i++)root[i]=i;
	for(int i=N; i>0; i/=4)ins(i, 0);
	for(int i=0; i<q; i++){
		if(Q[i].st){
			int l=pre[Q[i].nd.nd], r=post[Q[i].nd.nd];
			//cout<<l<<" "<<r<<"\n";
			int u=xo[Q[i].nd.st], ans=0;
			for(l+=N, r+=N; l<r; l>>=2, r>>=2){
				while((l&3) && l<r){
					ans=max(ans, find(l++, u));
				}
				while((r&3) && l<r){
					ans=max(ans, find(--r, u));
				}
			}
			cout<<ans<<"\n";
		}
		else{
			int t=pre[Q[i].nd.st], u=xo[Q[i].nd.st];
			t+=N;
			while(t){
				ins(t, u);
				t>>=2;
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 5 ms 8268 KB Output is correct
4 Correct 5 ms 8268 KB Output is correct
5 Correct 5 ms 8012 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 5 ms 8140 KB Output is correct
10 Correct 5 ms 8212 KB Output is correct
11 Correct 5 ms 8268 KB Output is correct
12 Correct 5 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 5 ms 8268 KB Output is correct
4 Correct 5 ms 8268 KB Output is correct
5 Correct 5 ms 8012 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 5 ms 8140 KB Output is correct
10 Correct 5 ms 8212 KB Output is correct
11 Correct 5 ms 8268 KB Output is correct
12 Correct 5 ms 8268 KB Output is correct
13 Correct 12 ms 8812 KB Output is correct
14 Correct 13 ms 9560 KB Output is correct
15 Correct 13 ms 10188 KB Output is correct
16 Correct 12 ms 10880 KB Output is correct
17 Correct 9 ms 8780 KB Output is correct
18 Correct 10 ms 9420 KB Output is correct
19 Correct 10 ms 10196 KB Output is correct
20 Correct 11 ms 10828 KB Output is correct
21 Correct 10 ms 8780 KB Output is correct
22 Correct 10 ms 9416 KB Output is correct
23 Correct 11 ms 10188 KB Output is correct
24 Correct 12 ms 10828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 736 ms 80064 KB Output is correct
2 Correct 677 ms 151128 KB Output is correct
3 Correct 843 ms 218024 KB Output is correct
4 Correct 892 ms 286480 KB Output is correct
5 Correct 1418 ms 81456 KB Output is correct
6 Correct 1478 ms 148296 KB Output is correct
7 Correct 1236 ms 213704 KB Output is correct
8 Correct 1414 ms 280272 KB Output is correct
9 Correct 1324 ms 81288 KB Output is correct
10 Correct 1314 ms 149068 KB Output is correct
11 Correct 1299 ms 215640 KB Output is correct
12 Correct 1049 ms 282024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 5 ms 8268 KB Output is correct
4 Correct 5 ms 8268 KB Output is correct
5 Correct 5 ms 8012 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 5 ms 8140 KB Output is correct
10 Correct 5 ms 8212 KB Output is correct
11 Correct 5 ms 8268 KB Output is correct
12 Correct 5 ms 8268 KB Output is correct
13 Correct 12 ms 8812 KB Output is correct
14 Correct 13 ms 9560 KB Output is correct
15 Correct 13 ms 10188 KB Output is correct
16 Correct 12 ms 10880 KB Output is correct
17 Correct 9 ms 8780 KB Output is correct
18 Correct 10 ms 9420 KB Output is correct
19 Correct 10 ms 10196 KB Output is correct
20 Correct 11 ms 10828 KB Output is correct
21 Correct 10 ms 8780 KB Output is correct
22 Correct 10 ms 9416 KB Output is correct
23 Correct 11 ms 10188 KB Output is correct
24 Correct 12 ms 10828 KB Output is correct
25 Correct 736 ms 80064 KB Output is correct
26 Correct 677 ms 151128 KB Output is correct
27 Correct 843 ms 218024 KB Output is correct
28 Correct 892 ms 286480 KB Output is correct
29 Correct 1418 ms 81456 KB Output is correct
30 Correct 1478 ms 148296 KB Output is correct
31 Correct 1236 ms 213704 KB Output is correct
32 Correct 1414 ms 280272 KB Output is correct
33 Correct 1324 ms 81288 KB Output is correct
34 Correct 1314 ms 149068 KB Output is correct
35 Correct 1299 ms 215640 KB Output is correct
36 Correct 1049 ms 282024 KB Output is correct
37 Correct 1698 ms 83824 KB Output is correct
38 Correct 1792 ms 151348 KB Output is correct
39 Correct 1539 ms 220128 KB Output is correct
40 Correct 1216 ms 286864 KB Output is correct
41 Correct 692 ms 81840 KB Output is correct
42 Correct 849 ms 148256 KB Output is correct
43 Correct 1086 ms 213860 KB Output is correct
44 Correct 1222 ms 280068 KB Output is correct
45 Correct 902 ms 81688 KB Output is correct
46 Correct 1000 ms 149052 KB Output is correct
47 Correct 999 ms 214780 KB Output is correct
48 Correct 965 ms 282096 KB Output is correct