This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
//#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=2e5+5;
const ll offset=1e9;
const ll block_sz=317;
const ll inf=1e18;
const ll mod=1e9+7;
int n;
struct TrieNode
{
TrieNode* child[2];
int cnt;
TrieNode()
{
child[0]=child[1]=nullptr;
cnt=inf;
}
};
TrieNode* root[maxn];
void Update(TrieNode* r, int u,int Time)
{
TrieNode* cur=r;
for2(i,29,0)
{
bool nxt=(u>>i)&1;
if (cur->child[nxt]==nullptr)
{
cur->child[nxt]=new TrieNode;
}
cur=cur->child[nxt];
cur->cnt=min(cur->cnt,Time);
}
}
int Get(TrieNode* r, int u,int Time)
{
int ans=0;
TrieNode* cur=r;
for2(i,29,0)
{
bool nxt=((u>>i)&1)^1;
//cerr<< nxt<<'\n';
if (cur->child[nxt]!=nullptr && cur->child[nxt]->cnt<=Time)
{
cur=cur->child[nxt];
ans+=(1<<i);
}
else
//if (cur->child[nxt|1]!=nullptr)
cur=cur->child[nxt^1];
//else cout << "wtf\n";
}
return ans;
}
int q,id[maxn];
string type;
int pre[maxn],ans[maxn];
vector<int> adj[maxn],L[maxn];
vector<pii> qr[maxn];
void dfs(int u)
{
// cerr<< u<<' '<<pre[u]<<'\n';
L[u].pb(u);
Update(root[u],pre[u],id[u]);
for(int v: adj[u])
{
// cerr<< v<<" asd\n";
dfs(v);
}
for(int v: adj[u])
{
if (L[v].size()>L[u].size())
{
L[u].swap(L[v]);
swap(root[u],root[v]);
}
for(int a:L[v])
{
L[u].pb(a);
Update(root[u],pre[a],id[a]);
}
}
//cerr<< u<< ' '<<L[u].size()<<" wtf\n";
//...
for(auto x: qr[u])
{
//cerr<< u<<' '<<x.se<<' '<<x.fi<<' '<<L[u].size()<<'\n';
ans[x.se]=Get(root[u],x.fi,x.se);
}
}
void sol()
{
cin >> q;
n=1;
for1(i,1,q)
{
ans[i]=-1;
int a,b;cin>> type>>a>>b;
if (type[0]=='A')
{
adj[a].pb(++n);
pre[n]=pre[a]^b;
id[n]=i;
}
else
{
qr[b].pb({pre[a],i});
}
}
for1(i,1,n) root[i]=new TrieNode;
// cerr<< "kk\n";
dfs(1);
for1(i,1,q) if (ans[i]!=-1) cout << ans[i]<<'\n';
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("GROUPDIV.inp","r",stdin);
// freopen("GROUPDIV.out","w",stdout);
int t=1;//cin >> t;
while (t--)
{
sol();
}
}
Compilation message (stderr)
klasika.cpp: In constructor 'TrieNode::TrieNode()':
klasika.cpp:36:13: warning: overflow in conversion from 'll' {aka 'long long int'} to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
36 | cnt=inf;
| ^~~
# | 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... |