#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
vector<pli>g[maxN];
ll val[maxN],in[maxN],out[maxN],tg=0;
void dfs(ll u=1)
{
in[u]=++tg;
for(auto vv:g[u])
{
val[vv.fi]=val[u]^vv.se;
dfs(vv.fi);
}
out[u]=tg;
}
struct TrieNode
{
TrieNode *child[2];
set<int>s;
TrieNode()
{
child[0]=child[1]=nullptr;
}
};
TrieNode *r=new TrieNode();
void add(ll u)
{
auto p=r;
for(int i=30;i>=0;i--)
{
ll x=val[u]>>i&1;
if(p->child[x]==nullptr)
{
p->child[x]=new TrieNode();
}
p=p->child[x];
p->s.insert(in[u]);
}
}
set<int>::iterator it;
ll get(ll x,ll l,ll rr)
{
auto p=r;
ll ans=0;
for(int i=30;i>=0;i--)
{
ll ut1=1,ut2=0;
if(x>>i&1) swap(ut1,ut2);
if(p->child[ut1]!=nullptr)
{
it=p->child[ut1]->s.lower_bound(l);
if(it!=p->child[ut1]->s.end()&&*it<=rr)
{
p=p->child[ut1];
ans+=(1<<i);
}
else
{
p=p->child[ut2];
}
}
else
{
p=p->child[ut2];
}
}
return ans;
}
ll q,c,x[maxN],y[maxN];
string s[maxN];
void solve()
{
cin >> q;
c=1;
for(int i=1;i<=q;i++)
{
cin >> s[i];
cin >> x[i] >> y[i];
if(s[i]=="Add")
{
c++;
g[x[i]].pb({c,y[i]});
}
}
val[1]=0;
dfs();
c=1;
for(int i=1;i<=q;i++)
{
if(s[i]=="Add")
{
c++;
add(c);
}
else
{
cout << get(val[x[i]],in[y[i]],out[y[i]])<<'\n';
}
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
22740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
22740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
70 ms |
37240 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
22740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |