Submission #348590

# Submission time Handle Problem Language Result Execution time Memory
348590 2021-01-15T09:06:05 Z Nima_Naderi Klasika (COCI20_klasika) C++14
110 / 110
3265 ms 439284 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(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	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';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB Output is correct
2 Correct 4 ms 5356 KB Output is correct
3 Correct 4 ms 5484 KB Output is correct
4 Correct 4 ms 5612 KB Output is correct
5 Correct 4 ms 5228 KB Output is correct
6 Correct 4 ms 5356 KB Output is correct
7 Correct 4 ms 5484 KB Output is correct
8 Correct 5 ms 5612 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 4 ms 5356 KB Output is correct
11 Correct 4 ms 5484 KB Output is correct
12 Correct 4 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB Output is correct
2 Correct 4 ms 5356 KB Output is correct
3 Correct 4 ms 5484 KB Output is correct
4 Correct 4 ms 5612 KB Output is correct
5 Correct 4 ms 5228 KB Output is correct
6 Correct 4 ms 5356 KB Output is correct
7 Correct 4 ms 5484 KB Output is correct
8 Correct 5 ms 5612 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 4 ms 5356 KB Output is correct
11 Correct 4 ms 5484 KB Output is correct
12 Correct 4 ms 5612 KB Output is correct
13 Correct 9 ms 6636 KB Output is correct
14 Correct 9 ms 7788 KB Output is correct
15 Correct 13 ms 9068 KB Output is correct
16 Correct 13 ms 10220 KB Output is correct
17 Correct 9 ms 6380 KB Output is correct
18 Correct 10 ms 7808 KB Output is correct
19 Correct 12 ms 8940 KB Output is correct
20 Correct 13 ms 10092 KB Output is correct
21 Correct 8 ms 6508 KB Output is correct
22 Correct 10 ms 7660 KB Output is correct
23 Correct 12 ms 8940 KB Output is correct
24 Correct 13 ms 10092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 864 ms 123896 KB Output is correct
2 Correct 1461 ms 230352 KB Output is correct
3 Correct 2023 ms 332268 KB Output is correct
4 Correct 2633 ms 435228 KB Output is correct
5 Correct 868 ms 122064 KB Output is correct
6 Correct 1483 ms 227216 KB Output is correct
7 Correct 2076 ms 328144 KB Output is correct
8 Correct 2682 ms 432552 KB Output is correct
9 Correct 880 ms 124752 KB Output is correct
10 Correct 1511 ms 231036 KB Output is correct
11 Correct 2131 ms 333552 KB Output is correct
12 Correct 2772 ms 434364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB Output is correct
2 Correct 4 ms 5356 KB Output is correct
3 Correct 4 ms 5484 KB Output is correct
4 Correct 4 ms 5612 KB Output is correct
5 Correct 4 ms 5228 KB Output is correct
6 Correct 4 ms 5356 KB Output is correct
7 Correct 4 ms 5484 KB Output is correct
8 Correct 5 ms 5612 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 4 ms 5356 KB Output is correct
11 Correct 4 ms 5484 KB Output is correct
12 Correct 4 ms 5612 KB Output is correct
13 Correct 9 ms 6636 KB Output is correct
14 Correct 9 ms 7788 KB Output is correct
15 Correct 13 ms 9068 KB Output is correct
16 Correct 13 ms 10220 KB Output is correct
17 Correct 9 ms 6380 KB Output is correct
18 Correct 10 ms 7808 KB Output is correct
19 Correct 12 ms 8940 KB Output is correct
20 Correct 13 ms 10092 KB Output is correct
21 Correct 8 ms 6508 KB Output is correct
22 Correct 10 ms 7660 KB Output is correct
23 Correct 12 ms 8940 KB Output is correct
24 Correct 13 ms 10092 KB Output is correct
25 Correct 864 ms 123896 KB Output is correct
26 Correct 1461 ms 230352 KB Output is correct
27 Correct 2023 ms 332268 KB Output is correct
28 Correct 2633 ms 435228 KB Output is correct
29 Correct 868 ms 122064 KB Output is correct
30 Correct 1483 ms 227216 KB Output is correct
31 Correct 2076 ms 328144 KB Output is correct
32 Correct 2682 ms 432552 KB Output is correct
33 Correct 880 ms 124752 KB Output is correct
34 Correct 1511 ms 231036 KB Output is correct
35 Correct 2131 ms 333552 KB Output is correct
36 Correct 2772 ms 434364 KB Output is correct
37 Correct 1506 ms 127608 KB Output is correct
38 Correct 2120 ms 233424 KB Output is correct
39 Correct 2531 ms 338640 KB Output is correct
40 Correct 2892 ms 439284 KB Output is correct
41 Correct 1570 ms 125648 KB Output is correct
42 Correct 2167 ms 230324 KB Output is correct
43 Correct 2582 ms 331596 KB Output is correct
44 Correct 2934 ms 431844 KB Output is correct
45 Correct 1701 ms 125200 KB Output is correct
46 Correct 2341 ms 231120 KB Output is correct
47 Correct 2752 ms 332364 KB Output is correct
48 Correct 3265 ms 434128 KB Output is correct