#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int q, cnt = 1, dp[N];
struct trie{
struct node{
node *c[2];
node(){c[0] = c[1] = 0;}
};
typedef node* pnode;
pnode rt = 0;
void upd(pnode &x, int v){
if(!x) x = new node();
pnode cur = x;
for(int i = 30;i>=0;i--){
int w;
if(v & (1 << i)) w = 1;
else w = 0;
if(!cur->c[w]) cur->c[w] = new node();
cur = cur->c[w];
}
}
int qry(pnode x, int v){
int mx = 0;
for(int i = 30;i>=0;i--){
int w;
if(v & (1 << i)) w = 0;
else w = 1;
if(x->c[w]){
mx += (1 << i);
x = x->c[w];
}else if(x->c[w ^ 1]){
x = x->c[w ^ 1];
}else{
break;
}
}
return mx;
}
}t;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> q;
t.upd(t.rt, 0);
for(int i = 1;i<=q;i++){
string tp;
cin >> tp;
if(tp == "Add"){
int u, w;
cin >> u >> w;
dp[++cnt] = (dp[u] ^ w);
t.upd(t.rt, dp[cnt]);
}else{
int a, b;
cin >> a >> b;
cout << t.qry(t.rt, dp[a]) << '\n';
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |