/**
* author: wxhtzdy
* created: 08.08.2022 17:17:05
**/
#include <bits/stdc++.h>
using namespace std;
struct node {
set<int> ids;
node *ch[2];
node() {
ch[0] = NULL;
ch[1] = NULL;
}
};
node root = node();
void Add(node *nd, int i, int v, int id) {
if (i < 0) {
return;
}
int bit = (v >> i & 1);
if (nd->ch[bit] == NULL) {
nd->ch[bit] = new node();
}
nd->ch[bit]->ids.insert(id);
Add(nd->ch[bit], i - 1, v, id);
}
int ans = 0;
void Go(node *nd, int i, int v, int L, int R) {
if (i < 0) {
return;
}
int bit = (v >> i & 1);
if (nd->ch[bit ^ 1] != NULL && nd->ch[bit ^ 1]->ids.lower_bound(L) != nd->ch[bit ^ 1]->ids.lower_bound(R + 1)) {
ans += (1 << i);
Go(nd->ch[bit ^ 1], i - 1, v, L, R);
} else {
Go(nd->ch[bit], i - 1, v, L, R);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
vector<string> op(q);
vector<int> x(q);
vector<int> y(q);
int n = 1;
vector<vector<pair<int, int>>> g(1);
for (int i = 0; i < q; i++) {
cin >> op[i] >> x[i] >> y[i];
if (op[i] == "Add") {
--x[i];
g.push_back({});
g[x[i]].emplace_back(n, y[i]);
n += 1;
} else {
--x[i]; --y[i];
}
}
vector<int> dep(n);
vector<int> tin(n);
vector<int> tout(n);
int T = -1;
function<void(int, int)> Dfs = [&](int v, int pr) {
tin[v] = ++T;
for (auto& p : g[v]) {
int u = p.first;
int w = p.second;
if (u != pr) {
dep[u] = dep[v] ^ w;
Dfs(u, v);
}
}
tout[v] = T;
};
Dfs(0, 0);
int idx = 1;
Add(&root, 30, dep[0], tin[0]);
for (int i = 0; i < q; i++) {
if (op[i] == "Add") {
Add(&root, 30, dep[idx], tin[idx]);
idx += 1;
} else {
ans = 0;
Go(&root, 30, dep[x[i]], tin[y[i]], tout[y[i]]);
cout << ans << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
832 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
832 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
1844 KB |
Output is correct |
14 |
Correct |
6 ms |
3076 KB |
Output is correct |
15 |
Correct |
6 ms |
4424 KB |
Output is correct |
16 |
Correct |
8 ms |
5500 KB |
Output is correct |
17 |
Correct |
4 ms |
1620 KB |
Output is correct |
18 |
Correct |
5 ms |
2900 KB |
Output is correct |
19 |
Correct |
8 ms |
4240 KB |
Output is correct |
20 |
Correct |
8 ms |
5316 KB |
Output is correct |
21 |
Correct |
4 ms |
1748 KB |
Output is correct |
22 |
Correct |
5 ms |
3028 KB |
Output is correct |
23 |
Correct |
8 ms |
4308 KB |
Output is correct |
24 |
Correct |
7 ms |
5360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
786 ms |
124496 KB |
Output is correct |
2 |
Correct |
1260 ms |
232580 KB |
Output is correct |
3 |
Correct |
1759 ms |
338800 KB |
Output is correct |
4 |
Correct |
2123 ms |
443312 KB |
Output is correct |
5 |
Correct |
682 ms |
122348 KB |
Output is correct |
6 |
Correct |
1195 ms |
226800 KB |
Output is correct |
7 |
Correct |
1620 ms |
326932 KB |
Output is correct |
8 |
Correct |
2081 ms |
426972 KB |
Output is correct |
9 |
Correct |
742 ms |
122340 KB |
Output is correct |
10 |
Correct |
1154 ms |
228388 KB |
Output is correct |
11 |
Correct |
1546 ms |
330340 KB |
Output is correct |
12 |
Correct |
1976 ms |
430484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
832 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
1844 KB |
Output is correct |
14 |
Correct |
6 ms |
3076 KB |
Output is correct |
15 |
Correct |
6 ms |
4424 KB |
Output is correct |
16 |
Correct |
8 ms |
5500 KB |
Output is correct |
17 |
Correct |
4 ms |
1620 KB |
Output is correct |
18 |
Correct |
5 ms |
2900 KB |
Output is correct |
19 |
Correct |
8 ms |
4240 KB |
Output is correct |
20 |
Correct |
8 ms |
5316 KB |
Output is correct |
21 |
Correct |
4 ms |
1748 KB |
Output is correct |
22 |
Correct |
5 ms |
3028 KB |
Output is correct |
23 |
Correct |
8 ms |
4308 KB |
Output is correct |
24 |
Correct |
7 ms |
5360 KB |
Output is correct |
25 |
Correct |
786 ms |
124496 KB |
Output is correct |
26 |
Correct |
1260 ms |
232580 KB |
Output is correct |
27 |
Correct |
1759 ms |
338800 KB |
Output is correct |
28 |
Correct |
2123 ms |
443312 KB |
Output is correct |
29 |
Correct |
682 ms |
122348 KB |
Output is correct |
30 |
Correct |
1195 ms |
226800 KB |
Output is correct |
31 |
Correct |
1620 ms |
326932 KB |
Output is correct |
32 |
Correct |
2081 ms |
426972 KB |
Output is correct |
33 |
Correct |
742 ms |
122340 KB |
Output is correct |
34 |
Correct |
1154 ms |
228388 KB |
Output is correct |
35 |
Correct |
1546 ms |
330340 KB |
Output is correct |
36 |
Correct |
1976 ms |
430484 KB |
Output is correct |
37 |
Correct |
1115 ms |
127400 KB |
Output is correct |
38 |
Correct |
1583 ms |
234948 KB |
Output is correct |
39 |
Correct |
1852 ms |
341468 KB |
Output is correct |
40 |
Correct |
2187 ms |
443944 KB |
Output is correct |
41 |
Correct |
1272 ms |
122872 KB |
Output is correct |
42 |
Correct |
1733 ms |
226668 KB |
Output is correct |
43 |
Correct |
2035 ms |
327104 KB |
Output is correct |
44 |
Correct |
2240 ms |
426268 KB |
Output is correct |
45 |
Correct |
1409 ms |
122844 KB |
Output is correct |
46 |
Correct |
1884 ms |
228420 KB |
Output is correct |
47 |
Correct |
2193 ms |
328996 KB |
Output is correct |
48 |
Correct |
2197 ms |
430288 KB |
Output is correct |