#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 10;
int sz;
struct node {
int to[2];
set <int> s;
} trie[Nmax * 31];
void add(int x, int ti) {
int u = 0;
for (int i = 29; i >= 0; --i) {
if (!trie[u].to[x >> i & 1]) trie[u].to[x >> i & 1] = ++sz;
u = trie[u].to[x >> i & 1];
trie[u].s.insert(ti);
}
}
int get(int x, int L, int R) {
int u = 0;
int ans = 0;
for (int i = 29; i >= 0; --i) {
auto iter = trie[trie[u].to[x >> i & 1 ^ 1]].s.lower_bound(L);
if (iter == trie[trie[u].to[x >> i & 1 ^ 1]].s.end() || *iter > R) u = trie[u].to[x >> i & 1];
else ans += (1 << i), u = trie[u].to[x >> i & 1 ^ 1];
}
return ans;
}
int q;
vector <pair <int, int> > e[Nmax];
int in[Nmax], out[Nmax], ti, d[Nmax];
void dfs(int u) {
in[u] = ++ti;
for (auto [v, w]: e[u]) {
d[v] = d[u] ^ w;
dfs(v);
}
out[u] = ti;
}
vector <tuple <string, int, int> > queries;
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> q;
int n = 1;
while (q--) {
string s;
int x, y;
cin >> s >> x >> y;
if (s == "Add") ++n, e[x].push_back({n, y}), queries.push_back({s, n, y});
else queries.push_back({s, x, y});
}
dfs(1);
add(d[1], in[1]);
for (auto [s, x, y]: queries) {
if (s == "Add") add(d[x], in[x]);
else cout << get(d[x], in[y], out[y]) << '\n';
}
}
Compilation message
klasika.cpp: In function 'int get(int, int, int)':
klasika.cpp:26:44: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
26 | auto iter = trie[trie[u].to[x >> i & 1 ^ 1]].s.lower_bound(L);
| ~~~~~~~^~~
klasika.cpp:27:44: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
27 | if (iter == trie[trie[u].to[x >> i & 1 ^ 1]].s.end() || *iter > R) u = trie[u].to[x >> i & 1];
| ~~~~~~~^~~
klasika.cpp:28:53: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
28 | else ans += (1 << i), u = trie[u].to[x >> i & 1 ^ 1];
| ~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
344760 KB |
Output is correct |
2 |
Correct |
166 ms |
344900 KB |
Output is correct |
3 |
Correct |
159 ms |
344936 KB |
Output is correct |
4 |
Correct |
158 ms |
344920 KB |
Output is correct |
5 |
Correct |
164 ms |
344732 KB |
Output is correct |
6 |
Correct |
193 ms |
344952 KB |
Output is correct |
7 |
Correct |
155 ms |
345028 KB |
Output is correct |
8 |
Correct |
166 ms |
344876 KB |
Output is correct |
9 |
Correct |
164 ms |
344772 KB |
Output is correct |
10 |
Correct |
157 ms |
345028 KB |
Output is correct |
11 |
Correct |
158 ms |
344868 KB |
Output is correct |
12 |
Correct |
166 ms |
344976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
344760 KB |
Output is correct |
2 |
Correct |
166 ms |
344900 KB |
Output is correct |
3 |
Correct |
159 ms |
344936 KB |
Output is correct |
4 |
Correct |
158 ms |
344920 KB |
Output is correct |
5 |
Correct |
164 ms |
344732 KB |
Output is correct |
6 |
Correct |
193 ms |
344952 KB |
Output is correct |
7 |
Correct |
155 ms |
345028 KB |
Output is correct |
8 |
Correct |
166 ms |
344876 KB |
Output is correct |
9 |
Correct |
164 ms |
344772 KB |
Output is correct |
10 |
Correct |
157 ms |
345028 KB |
Output is correct |
11 |
Correct |
158 ms |
344868 KB |
Output is correct |
12 |
Correct |
166 ms |
344976 KB |
Output is correct |
13 |
Correct |
165 ms |
345488 KB |
Output is correct |
14 |
Correct |
155 ms |
346068 KB |
Output is correct |
15 |
Correct |
166 ms |
346688 KB |
Output is correct |
16 |
Correct |
159 ms |
347120 KB |
Output is correct |
17 |
Correct |
155 ms |
345320 KB |
Output is correct |
18 |
Correct |
176 ms |
345972 KB |
Output is correct |
19 |
Correct |
160 ms |
346604 KB |
Output is correct |
20 |
Correct |
159 ms |
347084 KB |
Output is correct |
21 |
Correct |
157 ms |
345544 KB |
Output is correct |
22 |
Correct |
174 ms |
345984 KB |
Output is correct |
23 |
Correct |
173 ms |
346536 KB |
Output is correct |
24 |
Correct |
159 ms |
347024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
836 ms |
413916 KB |
Output is correct |
2 |
Correct |
1237 ms |
473912 KB |
Output is correct |
3 |
Runtime error |
1344 ms |
524292 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
344760 KB |
Output is correct |
2 |
Correct |
166 ms |
344900 KB |
Output is correct |
3 |
Correct |
159 ms |
344936 KB |
Output is correct |
4 |
Correct |
158 ms |
344920 KB |
Output is correct |
5 |
Correct |
164 ms |
344732 KB |
Output is correct |
6 |
Correct |
193 ms |
344952 KB |
Output is correct |
7 |
Correct |
155 ms |
345028 KB |
Output is correct |
8 |
Correct |
166 ms |
344876 KB |
Output is correct |
9 |
Correct |
164 ms |
344772 KB |
Output is correct |
10 |
Correct |
157 ms |
345028 KB |
Output is correct |
11 |
Correct |
158 ms |
344868 KB |
Output is correct |
12 |
Correct |
166 ms |
344976 KB |
Output is correct |
13 |
Correct |
165 ms |
345488 KB |
Output is correct |
14 |
Correct |
155 ms |
346068 KB |
Output is correct |
15 |
Correct |
166 ms |
346688 KB |
Output is correct |
16 |
Correct |
159 ms |
347120 KB |
Output is correct |
17 |
Correct |
155 ms |
345320 KB |
Output is correct |
18 |
Correct |
176 ms |
345972 KB |
Output is correct |
19 |
Correct |
160 ms |
346604 KB |
Output is correct |
20 |
Correct |
159 ms |
347084 KB |
Output is correct |
21 |
Correct |
157 ms |
345544 KB |
Output is correct |
22 |
Correct |
174 ms |
345984 KB |
Output is correct |
23 |
Correct |
173 ms |
346536 KB |
Output is correct |
24 |
Correct |
159 ms |
347024 KB |
Output is correct |
25 |
Correct |
836 ms |
413916 KB |
Output is correct |
26 |
Correct |
1237 ms |
473912 KB |
Output is correct |
27 |
Runtime error |
1344 ms |
524292 KB |
Execution killed with signal 9 |
28 |
Halted |
0 ms |
0 KB |
- |