답안 #250260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250260 2020-07-17T10:19:05 Z dvdg6566 Klasika (COCI20_klasika) C++14
110 / 110
3115 ms 439276 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end() 
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN=200001;
const ll MAXK=1000001;
const ll INF = 1e9;
const ll MOD = 1e9+7;

int A[MAXN];
vi V[MAXN];
int N,Q,a,b,c;
typedef pair<int,pi> pp;
vector<pp> X;
inline bool query(set<int> *x, int a,int b){
	auto t=x->lb(a);
	if(t==x->end())return 0;
	if(*t<=b)return 1;
	return 0;
}
int pre[MAXN],post[MAXN];

void dfs(int x){
	pre[x]=a;++a;
	for(auto v:V[x])dfs(v);
	post[x]=a-1;
}

struct node{
	int mult;
	set<int> S;
	node *z,*o;
	node(int ml):mult(ml){
		assert(mult>=-1);
		z=nullptr;
		o=nullptr;
	}
	void ins(int ind,int val){
		S.insert(ind);
		if(mult==-1){return;}
		if(val&(1<<mult)){
			if(!o)o=new node(mult-1);
			o->ins(ind,val);
		}else{
			if(!z)z=new node(mult-1);
			z->ins(ind,val);
		}
	}
	int ask(int x,int y,int p){
		if(mult==-1){
			assert(SZ(S));
			return 0;
		}
		// cerr<<SZ(S)<<' '<<mult<<'\n';
		if(!z&&!o)assert(0);
		if(p&(1<<mult)){ //u rather hv zero
			// cerr<<"Hi\n";
			if(!z)return o->ask(x,y,p);
			if(!query(&z->S,x,y))return o->ask(x,y,p);
			return (1<<mult)+z->ask(x,y,p);
		}else{
			if(!o)return z->ask(x,y,p);
			if(!query(&o->S,x,y))return z->ask(x,y,p);
			return (1<<mult)+o->ask(x,y,p);
		}
	}
}*root;

int main(){
	N=1;
	cin>>Q;
	for(int i=0;i<Q;++i){
		string S;cin>>S;
		cin>>a>>b;
		if(S[0]=='A')X.pb(1,mp(a,b));
		else X.pb(0,mp(a,b));
	}
	for(auto i:X)if(i.f==1){
		++N;
		A[N]=A[i.s.f]^i.s.s;
		V[i.s.f].pb(N);
	}
	a=1;
	dfs(1);
	root=new node(30);
	N=1;
	root->ins(1,0);
	for(auto i:X){
		pi t=i.s;
		if(i.f){ // inserting
			// cerr<<"Init "<<A[N]<<' '<<pre[N]<<'\n';
			++N;
			root->ins(pre[N],A[N]);
		}else{
			int s=A[t.f];
			// cerr<<"Asking for "<<pre[t.f]<<' '<<'\n';
			cout<<root->ask(pre[t.s],post[t.s],s)<<'\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5376 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5504 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5248 KB Output is correct
7 Correct 5 ms 5376 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 4 ms 5248 KB Output is correct
10 Correct 4 ms 5376 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 4 ms 5504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5376 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5504 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5248 KB Output is correct
7 Correct 5 ms 5376 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 4 ms 5248 KB Output is correct
10 Correct 4 ms 5376 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 4 ms 5504 KB Output is correct
13 Correct 8 ms 6528 KB Output is correct
14 Correct 11 ms 7808 KB Output is correct
15 Correct 13 ms 9088 KB Output is correct
16 Correct 14 ms 10204 KB Output is correct
17 Correct 10 ms 6400 KB Output is correct
18 Correct 12 ms 7680 KB Output is correct
19 Correct 12 ms 8960 KB Output is correct
20 Correct 15 ms 10112 KB Output is correct
21 Correct 8 ms 6400 KB Output is correct
22 Correct 12 ms 7680 KB Output is correct
23 Correct 12 ms 8960 KB Output is correct
24 Correct 13 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1039 ms 123608 KB Output is correct
2 Correct 1521 ms 233468 KB Output is correct
3 Correct 2131 ms 335984 KB Output is correct
4 Correct 2593 ms 438820 KB Output is correct
5 Correct 914 ms 125096 KB Output is correct
6 Correct 1603 ms 230692 KB Output is correct
7 Correct 2519 ms 331412 KB Output is correct
8 Correct 2868 ms 432480 KB Output is correct
9 Correct 1030 ms 124632 KB Output is correct
10 Correct 1545 ms 231208 KB Output is correct
11 Correct 2187 ms 333684 KB Output is correct
12 Correct 2758 ms 434540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5376 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5504 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5248 KB Output is correct
7 Correct 5 ms 5376 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 4 ms 5248 KB Output is correct
10 Correct 4 ms 5376 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 4 ms 5504 KB Output is correct
13 Correct 8 ms 6528 KB Output is correct
14 Correct 11 ms 7808 KB Output is correct
15 Correct 13 ms 9088 KB Output is correct
16 Correct 14 ms 10204 KB Output is correct
17 Correct 10 ms 6400 KB Output is correct
18 Correct 12 ms 7680 KB Output is correct
19 Correct 12 ms 8960 KB Output is correct
20 Correct 15 ms 10112 KB Output is correct
21 Correct 8 ms 6400 KB Output is correct
22 Correct 12 ms 7680 KB Output is correct
23 Correct 12 ms 8960 KB Output is correct
24 Correct 13 ms 10112 KB Output is correct
25 Correct 1039 ms 123608 KB Output is correct
26 Correct 1521 ms 233468 KB Output is correct
27 Correct 2131 ms 335984 KB Output is correct
28 Correct 2593 ms 438820 KB Output is correct
29 Correct 914 ms 125096 KB Output is correct
30 Correct 1603 ms 230692 KB Output is correct
31 Correct 2519 ms 331412 KB Output is correct
32 Correct 2868 ms 432480 KB Output is correct
33 Correct 1030 ms 124632 KB Output is correct
34 Correct 1545 ms 231208 KB Output is correct
35 Correct 2187 ms 333684 KB Output is correct
36 Correct 2758 ms 434540 KB Output is correct
37 Correct 1624 ms 127512 KB Output is correct
38 Correct 2200 ms 233556 KB Output is correct
39 Correct 2686 ms 338588 KB Output is correct
40 Correct 2928 ms 439276 KB Output is correct
41 Correct 1735 ms 125656 KB Output is correct
42 Correct 2283 ms 230328 KB Output is correct
43 Correct 2810 ms 331880 KB Output is correct
44 Correct 3115 ms 431912 KB Output is correct
45 Correct 1764 ms 125072 KB Output is correct
46 Correct 2680 ms 231176 KB Output is correct
47 Correct 2742 ms 332356 KB Output is correct
48 Correct 3054 ms 434168 KB Output is correct