Submission #224254

# Submission time Handle Problem Language Result Execution time Memory
224254 2020-04-17T15:17:12 Z jamielim Klasika (COCI20_klasika) C++14
110 / 110
3142 ms 441896 KB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
const int MAXN=200005;
const int BITS=30;
int n=1,q,ctr=1;
pair<int,pair<int,int> > query[MAXN];
vector<pair<int,int> > adj[MAXN];
int l[MAXN],r[MAXN],x[MAXN]; //discovery, finish, xor from root

struct trie{
	set<int> s;
	trie *z,*o;
	trie(){z=o=NULL;}
	void add(int h,int v,int idx){ //h: height, number of bits; v: value at subtree root; idx: discovery index being added
		s.insert(idx);
		if(h<0)return;
		if(v&(1<<h)){
			if(o==NULL)o=new trie();
			o->add(h-1,v,idx);
		}else{
			if(z==NULL)z=new trie();
			z->add(h-1,v,idx);
		}
	}
	int get(int h,int v,int fr,int to){ //h: height, number of bits; v: value of query node; [fr,to): range allowed
		if(h<0)return 0;
		if((v&(1<<h))==0){ //want 1
			if(o==NULL||o->s.lower_bound(fr)==o->s.lower_bound(to))return z->get(h-1,v,fr,to);
			return (1<<h)+o->get(h-1,v,fr,to);
		}else{ //want 0
			if(z==NULL||z->s.lower_bound(fr)==z->s.lower_bound(to))return o->get(h-1,v,fr,to);
			return (1<<h)+z->get(h-1,v,fr,to);
		}
	}
}*root=new trie();

void dfs(int u,int p,int v){
	l[u]=ctr++;
	x[u]=v;
	for(int i=0;i<(int)adj[u].size();i++){
		if(adj[u][i].first==p)continue;
		dfs(adj[u][i].first,u,v^adj[u][i].second);
	}
	r[u]=ctr;
}

int main(){
	scanf("%d",&q);
	char op[10];int a,b;
	for(int i=0;i<q;i++){
		scanf("%s%d%d",op,&a,&b);
		if(op[0]=='A'){
			n++;
			query[i]=mp(0,mp(a,b));
			adj[n].push_back(mp(a,b));
			adj[a].push_back(mp(n,b));
		}else{
			query[i]=mp(1,mp(a,b));
		}
	}
	dfs(1,0,0);
	root->add(BITS,0,l[1]);
	int nn=1;
	for(int i=0;i<q;i++){
		if(query[i].first==0){
			nn++;
			root->add(BITS,x[nn],l[nn]);
		}else{
			printf("%d\n",root->get(BITS,x[query[i].second.first],l[query[i].second.second],r[query[i].second.second]));
		}
	}
}

Compilation message

klasika.cpp: In function 'int main()':
klasika.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
klasika.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s%d%d",op,&a,&b);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 9 ms 5504 KB Output is correct
4 Correct 8 ms 5504 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 8 ms 5504 KB Output is correct
8 Correct 8 ms 5632 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 9 ms 5504 KB Output is correct
4 Correct 8 ms 5504 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 8 ms 5504 KB Output is correct
8 Correct 8 ms 5632 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5632 KB Output is correct
13 Correct 11 ms 6536 KB Output is correct
14 Correct 13 ms 7808 KB Output is correct
15 Correct 15 ms 9088 KB Output is correct
16 Correct 16 ms 10240 KB Output is correct
17 Correct 11 ms 6400 KB Output is correct
18 Correct 13 ms 7680 KB Output is correct
19 Correct 15 ms 8972 KB Output is correct
20 Correct 16 ms 10240 KB Output is correct
21 Correct 11 ms 6400 KB Output is correct
22 Correct 15 ms 7680 KB Output is correct
23 Correct 17 ms 8960 KB Output is correct
24 Correct 16 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1137 ms 122464 KB Output is correct
2 Correct 1528 ms 230460 KB Output is correct
3 Correct 1954 ms 333876 KB Output is correct
4 Correct 2737 ms 437808 KB Output is correct
5 Correct 869 ms 120696 KB Output is correct
6 Correct 1608 ms 226532 KB Output is correct
7 Correct 1947 ms 327928 KB Output is correct
8 Correct 2699 ms 429728 KB Output is correct
9 Correct 908 ms 120040 KB Output is correct
10 Correct 1667 ms 227320 KB Output is correct
11 Correct 1972 ms 330120 KB Output is correct
12 Correct 2864 ms 431352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 9 ms 5504 KB Output is correct
4 Correct 8 ms 5504 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 8 ms 5504 KB Output is correct
8 Correct 8 ms 5632 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5632 KB Output is correct
13 Correct 11 ms 6536 KB Output is correct
14 Correct 13 ms 7808 KB Output is correct
15 Correct 15 ms 9088 KB Output is correct
16 Correct 16 ms 10240 KB Output is correct
17 Correct 11 ms 6400 KB Output is correct
18 Correct 13 ms 7680 KB Output is correct
19 Correct 15 ms 8972 KB Output is correct
20 Correct 16 ms 10240 KB Output is correct
21 Correct 11 ms 6400 KB Output is correct
22 Correct 15 ms 7680 KB Output is correct
23 Correct 17 ms 8960 KB Output is correct
24 Correct 16 ms 10112 KB Output is correct
25 Correct 1137 ms 122464 KB Output is correct
26 Correct 1528 ms 230460 KB Output is correct
27 Correct 1954 ms 333876 KB Output is correct
28 Correct 2737 ms 437808 KB Output is correct
29 Correct 869 ms 120696 KB Output is correct
30 Correct 1608 ms 226532 KB Output is correct
31 Correct 1947 ms 327928 KB Output is correct
32 Correct 2699 ms 429728 KB Output is correct
33 Correct 908 ms 120040 KB Output is correct
34 Correct 1667 ms 227320 KB Output is correct
35 Correct 1972 ms 330120 KB Output is correct
36 Correct 2864 ms 431352 KB Output is correct
37 Correct 1658 ms 126456 KB Output is correct
38 Correct 2230 ms 233472 KB Output is correct
39 Correct 2347 ms 340064 KB Output is correct
40 Correct 2587 ms 441896 KB Output is correct
41 Correct 1727 ms 124000 KB Output is correct
42 Correct 2074 ms 229536 KB Output is correct
43 Correct 2648 ms 331564 KB Output is correct
44 Correct 2674 ms 432376 KB Output is correct
45 Correct 1756 ms 123308 KB Output is correct
46 Correct 2294 ms 230432 KB Output is correct
47 Correct 2893 ms 332516 KB Output is correct
48 Correct 3142 ms 434776 KB Output is correct