Submission #250261

# Submission time Handle Problem Language Result Execution time Memory
250261 2020-07-17T10:20:14 Z dvdg6566 Klasika (COCI20_klasika) C++14
110 / 110
2798 ms 436688 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 5248 KB Output is correct
2 Correct 4 ms 5248 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5632 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 5 ms 5376 KB Output is correct
7 Correct 4 ms 5376 KB Output is correct
8 Correct 4 ms 5632 KB Output is correct
9 Correct 3 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 5632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5248 KB Output is correct
2 Correct 4 ms 5248 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5632 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 5 ms 5376 KB Output is correct
7 Correct 4 ms 5376 KB Output is correct
8 Correct 4 ms 5632 KB Output is correct
9 Correct 3 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 5632 KB Output is correct
13 Correct 7 ms 6528 KB Output is correct
14 Correct 8 ms 7808 KB Output is correct
15 Correct 11 ms 9088 KB Output is correct
16 Correct 18 ms 10240 KB Output is correct
17 Correct 7 ms 6400 KB Output is correct
18 Correct 10 ms 7680 KB Output is correct
19 Correct 11 ms 8960 KB Output is correct
20 Correct 12 ms 10112 KB Output is correct
21 Correct 7 ms 6528 KB Output is correct
22 Correct 9 ms 7680 KB Output is correct
23 Correct 10 ms 8960 KB Output is correct
24 Correct 12 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 829 ms 125016 KB Output is correct
2 Correct 1282 ms 233304 KB Output is correct
3 Correct 1827 ms 335720 KB Output is correct
4 Correct 2419 ms 436688 KB Output is correct
5 Correct 751 ms 123764 KB Output is correct
6 Correct 1403 ms 228768 KB Output is correct
7 Correct 2020 ms 329568 KB Output is correct
8 Correct 2606 ms 430040 KB Output is correct
9 Correct 756 ms 123000 KB Output is correct
10 Correct 1322 ms 229080 KB Output is correct
11 Correct 1767 ms 331352 KB Output is correct
12 Correct 2458 ms 431704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5248 KB Output is correct
2 Correct 4 ms 5248 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5632 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 5 ms 5376 KB Output is correct
7 Correct 4 ms 5376 KB Output is correct
8 Correct 4 ms 5632 KB Output is correct
9 Correct 3 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 5632 KB Output is correct
13 Correct 7 ms 6528 KB Output is correct
14 Correct 8 ms 7808 KB Output is correct
15 Correct 11 ms 9088 KB Output is correct
16 Correct 18 ms 10240 KB Output is correct
17 Correct 7 ms 6400 KB Output is correct
18 Correct 10 ms 7680 KB Output is correct
19 Correct 11 ms 8960 KB Output is correct
20 Correct 12 ms 10112 KB Output is correct
21 Correct 7 ms 6528 KB Output is correct
22 Correct 9 ms 7680 KB Output is correct
23 Correct 10 ms 8960 KB Output is correct
24 Correct 12 ms 10112 KB Output is correct
25 Correct 829 ms 125016 KB Output is correct
26 Correct 1282 ms 233304 KB Output is correct
27 Correct 1827 ms 335720 KB Output is correct
28 Correct 2419 ms 436688 KB Output is correct
29 Correct 751 ms 123764 KB Output is correct
30 Correct 1403 ms 228768 KB Output is correct
31 Correct 2020 ms 329568 KB Output is correct
32 Correct 2606 ms 430040 KB Output is correct
33 Correct 756 ms 123000 KB Output is correct
34 Correct 1322 ms 229080 KB Output is correct
35 Correct 1767 ms 331352 KB Output is correct
36 Correct 2458 ms 431704 KB Output is correct
37 Correct 1342 ms 125176 KB Output is correct
38 Correct 2317 ms 230868 KB Output is correct
39 Correct 2507 ms 335840 KB Output is correct
40 Correct 2535 ms 436140 KB Output is correct
41 Correct 1503 ms 122980 KB Output is correct
42 Correct 2090 ms 227364 KB Output is correct
43 Correct 2660 ms 328556 KB Output is correct
44 Correct 2798 ms 428256 KB Output is correct
45 Correct 1742 ms 121988 KB Output is correct
46 Correct 2073 ms 227984 KB Output is correct
47 Correct 2392 ms 328936 KB Output is correct
48 Correct 2771 ms 430188 KB Output is correct