/*
_.-- ,.--.
.' .' /
@ |'..--------._
/ \._/ '.
/ .-.- \
( / \ \
\\ '. | #
\\ \ -. /
:\ | )._____.' \
" | / \ | \ )
| |./' :__ \.-'
'--'
*/
#include<bits/stdc++.h>
#define ll long long
#define llll pair<int,int>
#define ii pair<int,int>
#define fi first
#define se second
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define ull unsigned long long
#define iii pair<int,pii>
#define iv pair<pii,pii>
#define db double
#define ld long double
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyy[] = {2, -2, 2, -2, 1, -1, 1, -1};
const ll INF=1e18;
struct node
{
node *a[2];
set<int> s;
node()
{
a[0]=a[1]=NULL;
}
};
const int N=2e5+5;
vector<pair<bool,ii>>Query;
int l[N],r[N],n,timer,sx[N],ans[N],cc;
vector<ii> a[N];
void dfs(int u=1,int cur=0)
{
l[u]=++timer;
sx[u]=cur;
for(int i=0;i<a[u].size();i++)
{
int v=a[u][i].fi,xo=a[u][i].se;
dfs(v,cur^xo);
}
r[u]=timer;
}
void update(int pos,int v,node *p)
{
// cout << ":: " << v << "::" << ' ';
for(int i=30;i>=0;i--)
{
int bit=((v>>i)&1);
if(p->a[bit]==NULL)
{
p->a[bit]=new node();
}
// cout << bit << ' ';
p=p->a[bit];
p->s.insert(pos);
}
}
int get(int u,int v,int val,node *p)
{
int ret=0;
for(int i=30;i>=0;i--)
{
int bit=((val>>i)&1);
if(p->a[1-bit]==NULL or lower_bound(p->a[1-bit]->s.begin(),p->a[1-bit]->s.end(),u)==upper_bound(p->a[1-bit]->s.begin(),p->a[1-bit]->s.end(),v))
{
p=p->a[bit];
}
else
{
ret+=(1<<i);
p=p->a[1-bit];
}
}
return ret;
}
void solve()
{
scanf("%d",&n);
node *root=new node();
int cnt=1;
for(int i=1;i<=n;i++)
{
char type[10];
int x,y;
scanf("%s%d%d",&type,&x,&y);
if(type[0]=='A')
{
cnt++;
a[x].push_back({cnt,y});
Query.push_back({0,{cnt,-1}});
}
else
{
Query.pb({1,{x,y}});
}
}
dfs();
// for(int i=1;i<=cnt;i++)
// {
// cout << sx[i] << " \n"[i==cnt];
// }
update(1,0,root);
// cout << '\n';
for(auto q:Query)
{
if(q.fi)
{
// cout << sx[q.x] << '\n';
printf("%d\n",get(l[q.se.se],r[q.se.se],sx[q.se.fi],root));
}
else
{
// cout << q.x << '\n';
update(l[q.se.fi],sx[q.se.fi],root);
// cout << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen("tdk.inp","r",stdin);
// freopen("tdk.out","w",stdout);
int t=1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
}
Compilation message (stderr)
klasika.cpp: In function 'void solve()':
klasika.cpp:107:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[10]' [-Wformat=]
107 | scanf("%s%d%d",&type,&x,&y);
| ~^ ~~~~~
| | |
| char* char (*)[10]
klasika.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
klasika.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%s%d%d",&type,&x,&y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |