답안 #459656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459656 2021-08-08T22:28:34 Z Antekb Klasika (COCI20_klasika) C++14
33 / 110
5000 ms 14572 KB
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
const int N = (1<<18), M=6e7;
int pre[N], post[N], xo[N];
vector<int> E[N];
int L[M], R[M];
int wsk;
int root[N+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=2*N;
	for(int i=1; i<2*N; i++)root[i]=i;
	const int L=500;
	//for(int i=N; i>0; i>>=1)ins(i, 0);
	ins(L+1, 0);
	ins(1, 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>>=1, r>>=1){
				if(l&1){
					ans=max(ans, find(root[l++], u));
				}
				if(r&1){
					ans=max(ans, find(root[--r], u));
				}
			}*/
			while(l<r){
				ans=max(ans, find(l+L+1, u));
				l++;
			}
			while(l<r && r%L){
				ans=max(ans, find((--r)+L+1, u));
			}
			l/=L;
			r/=L;
			while(l<r){
				ans=max(ans, find(l+1, u));
				l++;
			}
			cout<<ans<<"\n";
		}
		else{
			int t=pre[Q[i].nd.st], u=xo[Q[i].nd.st];
			ins(t+L+1, u);
			ins(t/L+1, u);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8524 KB Output is correct
2 Correct 7 ms 8508 KB Output is correct
3 Correct 7 ms 8524 KB Output is correct
4 Correct 7 ms 8636 KB Output is correct
5 Correct 6 ms 8544 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 6 ms 8508 KB Output is correct
8 Correct 6 ms 8524 KB Output is correct
9 Correct 6 ms 8508 KB Output is correct
10 Correct 6 ms 8508 KB Output is correct
11 Correct 6 ms 8524 KB Output is correct
12 Correct 6 ms 8524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8524 KB Output is correct
2 Correct 7 ms 8508 KB Output is correct
3 Correct 7 ms 8524 KB Output is correct
4 Correct 7 ms 8636 KB Output is correct
5 Correct 6 ms 8544 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 6 ms 8508 KB Output is correct
8 Correct 6 ms 8524 KB Output is correct
9 Correct 6 ms 8508 KB Output is correct
10 Correct 6 ms 8508 KB Output is correct
11 Correct 6 ms 8524 KB Output is correct
12 Correct 6 ms 8524 KB Output is correct
13 Correct 78 ms 8732 KB Output is correct
14 Correct 109 ms 8956 KB Output is correct
15 Correct 109 ms 9412 KB Output is correct
16 Correct 76 ms 9256 KB Output is correct
17 Correct 12 ms 8780 KB Output is correct
18 Correct 13 ms 8908 KB Output is correct
19 Correct 11 ms 9164 KB Output is correct
20 Correct 10 ms 9288 KB Output is correct
21 Correct 22 ms 8776 KB Output is correct
22 Correct 24 ms 8908 KB Output is correct
23 Correct 30 ms 9164 KB Output is correct
24 Correct 21 ms 9288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5060 ms 14572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8524 KB Output is correct
2 Correct 7 ms 8508 KB Output is correct
3 Correct 7 ms 8524 KB Output is correct
4 Correct 7 ms 8636 KB Output is correct
5 Correct 6 ms 8544 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 6 ms 8508 KB Output is correct
8 Correct 6 ms 8524 KB Output is correct
9 Correct 6 ms 8508 KB Output is correct
10 Correct 6 ms 8508 KB Output is correct
11 Correct 6 ms 8524 KB Output is correct
12 Correct 6 ms 8524 KB Output is correct
13 Correct 78 ms 8732 KB Output is correct
14 Correct 109 ms 8956 KB Output is correct
15 Correct 109 ms 9412 KB Output is correct
16 Correct 76 ms 9256 KB Output is correct
17 Correct 12 ms 8780 KB Output is correct
18 Correct 13 ms 8908 KB Output is correct
19 Correct 11 ms 9164 KB Output is correct
20 Correct 10 ms 9288 KB Output is correct
21 Correct 22 ms 8776 KB Output is correct
22 Correct 24 ms 8908 KB Output is correct
23 Correct 30 ms 9164 KB Output is correct
24 Correct 21 ms 9288 KB Output is correct
25 Execution timed out 5060 ms 14572 KB Time limit exceeded
26 Halted 0 ms 0 KB -