답안 #291245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291245 2020-09-04T23:41:10 Z penguinhacker Klasika (COCI20_klasika) C++17
66 / 110
4726 ms 47320 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int MAXDIG=30;
struct Node {
	int nxt[2];
	Node() {nxt[0]=nxt[1]=-1;}
};
struct Trie {
	vector<Node> trie;
	Trie() {trie.emplace_back();}
	void add(int x) {
		int cur=0;
		for (int i=MAXDIG; ~i; --i) {
			int c=(x>>i)&1;
			if (trie[cur].nxt[c]==-1) {
				trie[cur].nxt[c]=trie.size();
				trie.emplace_back();
			}
			cur=trie[cur].nxt[c];
		}
	}

	int qry(int x) { //best xor in trie 
		int cur=0;
		int res=0;
		for (int i=MAXDIG; ~i; --i) {
			int c=(x>>i)&1;
			if (trie[cur].nxt[c^1]!=-1) {
				res+=(1<<i);
				cur=trie[cur].nxt[c^1];
			}
			else {
				cur=trie[cur].nxt[c];
			}
		}
		return res;
	}
} trie;

const int mxN=2e5;
int n=1, val[mxN];
vector<int> adj[mxN];

int dfs(int u, int x) {
	int MX=x^val[u];
	for (int v: adj[u]) {
		MX=max(MX, dfs(v, x));
	}
	return MX;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	trie.add(0);
	int q; cin >> q;
	while(q--) {
		string type; cin >> type;
		int a, b; cin >> a >> b;
		if (type=="Add") {
			--a;
			val[n]=val[a]^b;
			adj[a].push_back(n);
			trie.add(val[n]);
			++n;
		}
		if (type=="Query") {
			--a, --b;
			int ans=q<=2000?dfs(b, val[a]):trie.qry(val[a]);
			cout << ans << "\n";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 3 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 3 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 5 ms 5248 KB Output is correct
14 Correct 6 ms 5504 KB Output is correct
15 Correct 6 ms 5528 KB Output is correct
16 Correct 6 ms 5784 KB Output is correct
17 Correct 4 ms 5248 KB Output is correct
18 Correct 5 ms 5504 KB Output is correct
19 Correct 5 ms 5388 KB Output is correct
20 Correct 5 ms 5388 KB Output is correct
21 Correct 5 ms 5248 KB Output is correct
22 Correct 5 ms 5504 KB Output is correct
23 Correct 5 ms 5392 KB Output is correct
24 Correct 5 ms 5392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 651 ms 15992 KB Output is correct
2 Correct 1298 ms 28012 KB Output is correct
3 Correct 1597 ms 32600 KB Output is correct
4 Correct 1367 ms 47320 KB Output is correct
5 Correct 1712 ms 17728 KB Output is correct
6 Correct 3009 ms 26976 KB Output is correct
7 Correct 4726 ms 25568 KB Output is correct
8 Correct 4469 ms 44876 KB Output is correct
9 Correct 1025 ms 18160 KB Output is correct
10 Correct 1577 ms 27236 KB Output is correct
11 Correct 1823 ms 26860 KB Output is correct
12 Correct 1568 ms 45648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 3 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 5 ms 5248 KB Output is correct
14 Correct 6 ms 5504 KB Output is correct
15 Correct 6 ms 5528 KB Output is correct
16 Correct 6 ms 5784 KB Output is correct
17 Correct 4 ms 5248 KB Output is correct
18 Correct 5 ms 5504 KB Output is correct
19 Correct 5 ms 5388 KB Output is correct
20 Correct 5 ms 5388 KB Output is correct
21 Correct 5 ms 5248 KB Output is correct
22 Correct 5 ms 5504 KB Output is correct
23 Correct 5 ms 5392 KB Output is correct
24 Correct 5 ms 5392 KB Output is correct
25 Correct 651 ms 15992 KB Output is correct
26 Correct 1298 ms 28012 KB Output is correct
27 Correct 1597 ms 32600 KB Output is correct
28 Correct 1367 ms 47320 KB Output is correct
29 Correct 1712 ms 17728 KB Output is correct
30 Correct 3009 ms 26976 KB Output is correct
31 Correct 4726 ms 25568 KB Output is correct
32 Correct 4469 ms 44876 KB Output is correct
33 Correct 1025 ms 18160 KB Output is correct
34 Correct 1577 ms 27236 KB Output is correct
35 Correct 1823 ms 26860 KB Output is correct
36 Correct 1568 ms 45648 KB Output is correct
37 Incorrect 403 ms 18804 KB Output isn't correct
38 Halted 0 ms 0 KB -