Submission #223367

# Submission time Handle Problem Language Result Execution time Memory
223367 2020-04-15T08:08:22 Z oolimry Klasika (COCI20_klasika) C++14
66 / 110
2920 ms 460388 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int n = 1;
int cnt = 0;
static vector<int> adj[200005];
static int low[200005];
static int high[200005];
static int XOR[200005];
 
void dfs(int u){
	low[u] = cnt;
	high[u] = cnt;
	cnt++;
	for(int v : adj[u]){
		dfs(v);
		high[u] = max(high[u], high[v]);
	}
}
 
typedef pair<int,int> ii;
vector<ii> queries;

int N = 0;

static ii trie[4000005];
static set<int> S[4000005];
int CNT = 2;

void INS(int x, int pos){
	int u = 1;
	for(int b = 30;b >= 0;b--){
		if((x & (1<<b)) == 0){
			if(trie[u].first == 0){
				trie[u].first = CNT;
				CNT++;
			}
			u = trie[u].first;
		}
		else{
			if(trie[u].second == 0){
				trie[u].second = CNT;
				CNT++;
			}
			u = trie[u].second;
		}
		S[u].insert(pos);
	}
}

int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int Q; cin >> Q;
	queries.push_back(ii(-1,0));
	
	for(int q = 0;q < Q;q++){
		string s; int a, b; 
		cin >> s >> a >> b;
		if(s[0] == 'A' || s[0] == 'a'){
			a--;
			assert(a < n);
			adj[a].push_back(n);
			XOR[n] = XOR[a] ^ b;
			queries.push_back(ii(-1,n));
			n++;
		}
		else{
			assert(a-1 < n);
			assert(b-1 < n);
			queries.push_back(ii(a-1,b-1));
		}
	}
	
	
	dfs(0);
	
	for(ii q : queries){
		//cout << q.first << " " << q.second << "\n";
		
		if(q.first == -1){
			int pos = low[q.second];
			int x = XOR[q.second];
			
			INS(x, pos);
			
			continue;
		}
		
		int other = XOR[q.first];
		int L = low[q.second], R = high[q.second];
		int cur = 0;
		
		int u = 1;
		for(int b = 30;b >= 0;b--){
			int pref = trie[u].first;
			int nopref = trie[u].second;
			
			if(pref == 0){
				cur ^= (1 << b);
				u = nopref; continue;
			}
			if(nopref == 0){
				u = pref; continue;
			}
			
			if((other & (1<<b)) == 0){
				swap(pref, nopref);
				cur ^= (1 << b);
			}
			
			if(Q <= 2000){
				set<int> s = S[pref];
				auto it = s.lower_bound(L);
				if(it == s.end() || *it > R){
					cur ^= (1 << b);
					u = nopref;
				}
				else u = pref;
			}
			else u = pref;
			
		}
		
		cout << (cur ^ other) << "\n";
		
	}
}
# Verdict Execution time Memory Grader output
1 Correct 110 ms 193016 KB Output is correct
2 Correct 108 ms 193020 KB Output is correct
3 Correct 110 ms 193144 KB Output is correct
4 Correct 112 ms 193192 KB Output is correct
5 Correct 111 ms 193016 KB Output is correct
6 Correct 108 ms 193016 KB Output is correct
7 Correct 109 ms 193272 KB Output is correct
8 Correct 111 ms 193144 KB Output is correct
9 Correct 110 ms 193016 KB Output is correct
10 Correct 109 ms 193016 KB Output is correct
11 Correct 109 ms 193144 KB Output is correct
12 Correct 109 ms 193144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 193016 KB Output is correct
2 Correct 108 ms 193020 KB Output is correct
3 Correct 110 ms 193144 KB Output is correct
4 Correct 112 ms 193192 KB Output is correct
5 Correct 111 ms 193016 KB Output is correct
6 Correct 108 ms 193016 KB Output is correct
7 Correct 109 ms 193272 KB Output is correct
8 Correct 111 ms 193144 KB Output is correct
9 Correct 110 ms 193016 KB Output is correct
10 Correct 109 ms 193016 KB Output is correct
11 Correct 109 ms 193144 KB Output is correct
12 Correct 109 ms 193144 KB Output is correct
13 Correct 131 ms 193656 KB Output is correct
14 Correct 131 ms 194428 KB Output is correct
15 Correct 137 ms 195064 KB Output is correct
16 Correct 131 ms 195704 KB Output is correct
17 Correct 134 ms 193708 KB Output is correct
18 Correct 143 ms 194296 KB Output is correct
19 Correct 139 ms 194936 KB Output is correct
20 Correct 135 ms 195704 KB Output is correct
21 Correct 131 ms 193656 KB Output is correct
22 Correct 139 ms 194296 KB Output is correct
23 Correct 139 ms 194936 KB Output is correct
24 Correct 131 ms 195576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 666 ms 262724 KB Output is correct
2 Correct 1253 ms 329964 KB Output is correct
3 Correct 1858 ms 394468 KB Output is correct
4 Correct 2507 ms 460388 KB Output is correct
5 Correct 719 ms 261660 KB Output is correct
6 Correct 1417 ms 325228 KB Output is correct
7 Correct 2131 ms 387628 KB Output is correct
8 Correct 2920 ms 450868 KB Output is correct
9 Correct 687 ms 261296 KB Output is correct
10 Correct 1316 ms 326148 KB Output is correct
11 Correct 1922 ms 389880 KB Output is correct
12 Correct 2629 ms 452836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 193016 KB Output is correct
2 Correct 108 ms 193020 KB Output is correct
3 Correct 110 ms 193144 KB Output is correct
4 Correct 112 ms 193192 KB Output is correct
5 Correct 111 ms 193016 KB Output is correct
6 Correct 108 ms 193016 KB Output is correct
7 Correct 109 ms 193272 KB Output is correct
8 Correct 111 ms 193144 KB Output is correct
9 Correct 110 ms 193016 KB Output is correct
10 Correct 109 ms 193016 KB Output is correct
11 Correct 109 ms 193144 KB Output is correct
12 Correct 109 ms 193144 KB Output is correct
13 Correct 131 ms 193656 KB Output is correct
14 Correct 131 ms 194428 KB Output is correct
15 Correct 137 ms 195064 KB Output is correct
16 Correct 131 ms 195704 KB Output is correct
17 Correct 134 ms 193708 KB Output is correct
18 Correct 143 ms 194296 KB Output is correct
19 Correct 139 ms 194936 KB Output is correct
20 Correct 135 ms 195704 KB Output is correct
21 Correct 131 ms 193656 KB Output is correct
22 Correct 139 ms 194296 KB Output is correct
23 Correct 139 ms 194936 KB Output is correct
24 Correct 131 ms 195576 KB Output is correct
25 Correct 666 ms 262724 KB Output is correct
26 Correct 1253 ms 329964 KB Output is correct
27 Correct 1858 ms 394468 KB Output is correct
28 Correct 2507 ms 460388 KB Output is correct
29 Correct 719 ms 261660 KB Output is correct
30 Correct 1417 ms 325228 KB Output is correct
31 Correct 2131 ms 387628 KB Output is correct
32 Correct 2920 ms 450868 KB Output is correct
33 Correct 687 ms 261296 KB Output is correct
34 Correct 1316 ms 326148 KB Output is correct
35 Correct 1922 ms 389880 KB Output is correct
36 Correct 2629 ms 452836 KB Output is correct
37 Incorrect 684 ms 263956 KB Output isn't correct
38 Halted 0 ms 0 KB -