#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=2e5+5;
vector<int>g[mxn];
int d[mxn]{0},tin[mxn]{0},tout[mxn]{0},cu=0,n;
void dfs(int u){
tin[u]=++cu;
for(auto v:g[u]){
dfs(v);
}tout[u]=cu;
}
multiset<int>t[4*mxn];
void update(int i,int l,int r,int idx,int v){
if(r<idx||l>idx)return;
if(l==r){
t[i].insert(v);return;
}int m=(l+r)>>1;
update(2*i,l,m,idx,v);update(2*i+1,m+1,r,idx,v);
t[i].insert(v);
}
bool qr(int i,int l,int r,int tl,int tr,int rs,int id){
if(r<tl||l>tr)return 0;
if(r<=tr&&l>=tl){
auto it = t[i].lower_bound(rs);
if(it==t[i].end())return 0;
return ((rs>>id)==((*it)>>id));
}
int m=(l+r)>>1;
return (qr(2*i,l,m,tl,tr,rs,id)||qr(2*i+1,m+1,r,tl,tr,rs,id));
}
void solve(int a,int b){
int ans = 0;
for(int i=30;i>=0;i--){
int x=((d[a]>>i)&1)^1;
int y=x*(1<<i);
ans|=y;
bool rs=qr(1,1,n,tin[b],tout[b],ans,i);
if(!rs)ans^=(1<<i);
}cout<<(d[a]^ans)<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int x;cin>>n;x=1;
vector<pair<int,pii>>qr;
for(int i=1;i<=n;i++){
string s;int a,b;cin>>s>>a>>b;
if(s=="Add"){
x++;d[x]=d[a]^b;g[a].pb(x);
qr.pb({1,{x,b}});
}
else qr.pb({2,{a,b}});
}dfs(1);n=x;
update(1,1,n,tin[1],d[1]);
for(auto it : qr){
auto [a,b] = it.s;
if(it.f==1)update(1,1,n,tin[a],d[a]);
else solve(a,b);
}
}
# | 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... |