#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 10, LG = 31;
ll q, n = 2, par[N][LG], sp[N][LG], h[N];
ll sz = 1, nxt[N * 31][2];
void add(ll x){
ll cur = 0;
for (ll i = 30; i >= 0; i --){
int b = (((1ll << i) & x) > 0);
if (nxt[cur][b] == -1)
nxt[cur][b] = sz++;
cur = nxt[cur][b];
}
}
ll get(ll x){
ll cur = 0;
ll res = 0;
for (ll i = 30; i >= 0; i --){
int b = (((1ll << i) & x) > 0);
if (nxt[cur][1 - b] != -1){
cur = nxt[cur][1 - b];
res |= (1ll << i);
}
else
cur = nxt[cur][b];
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(par, -1, sizeof par);
memset(nxt, -1, sizeof nxt);
cin >> q;
while (q--){
string s;
cin >> s;
if (s == "Add"){
ll x, y;
cin >> x >> y;
par[n][0] = x;
sp[n][0] = y;
for (ll i = 1; i < LG; i ++){
if (par[n][i - 1] == -1) continue;
par[n][i] = par[par[n][i - 1]][i - 1];
sp[n][i] = sp[n][i - 1] ^ sp[par[n][i - 1]][i - 1];
}
h[n] = h[x] + 1;
ll v = n;
ll d = h[v] - h[1];
ll val = 0;
for (ll i = 0; i < LG; i ++){
if ((1ll << i) & d){
val ^= sp[v][i];
v = par[v][i];
}
}
add(val);
// cout << "adding " << val << " in trie" << endl;
n++;
}
else{
ll a, b;
cin >> a >> b;
ll v = a;
ll d = h[v] - h[1];
ll val = 0;
for (ll i = 0; i < LG; i ++){
if ((1ll << i) & d){
val ^= sp[v][i];
v = par[v][i];
}
}
// cout << "getting from " << val << endl;
cout << get(val) << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
145996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
145996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
187 ms |
160592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
145996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |