#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;
const int inf = 2e18 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
vector<pair<int, int> > adj[N];
vector<int> valxor(N);
struct node{
int to[2];
int cnt;
node(){
to[0] = to[1] = -1;
cnt = 0;
}
};
vector<node> t;
void add(int x){
int v = 0;
for(int i = 29; i >= 0; i--){
int c = ((x & (1 << i)) > 0);
if(t[v].to[c] == -1){
t[v].to[c] = t.size();
t.pb(node());
t[v].cnt++;
}
v = t[v].to[c];
}
t[v].cnt++;
}
int solve(int v, int k, int tp, int val){
if(tp < 0) return val;
int mask = (k & (1 << tp) ? 0 : 1);
if(t[v].to[mask] != -1){
//cout<<"aldim "<<val<<" "<<tp<<" "<<t[v].to[mask]<<endl;
return solve(t[v].to[mask], k, tp-1, val + (1 << tp));
}
else{
//cout<<"alamadim "<<val + (1 << tp)<<endl;
return solve(t[v].to[mask^1], k, tp-1, val);
}
}
int32_t main(){
//freopen("in.txt","r", stdin);
t.pb(node());
int q;
cin>>q;
int ncnt = 1;
valxor[1] = 0;
while(q--){
string s;
cin>>s;
if(s == "Add"){
int x, y;
cin>>x>>y;
ncnt++;
adj[ncnt].pb({x, y});
adj[x].pb({ncnt, y});
valxor[ncnt] = (valxor[x] ^ y);
add(valxor[ncnt]);
}
else{
int a, b; // b == 1
cin>>a>>b;
int ans = 0, add = valxor[a];
ans = solve(0, valxor[a], 29, 0);
cout<<ans<<endl;
}
}
return 0;
}
Compilation message
klasika.cpp: In function 'int32_t main()':
klasika.cpp:78:22: warning: unused variable 'add' [-Wunused-variable]
78 | int ans = 0, add = valxor[a];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
374 ms |
36900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |