# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940898 | User0069 | Klasika (COCI20_klasika) | C++17 | 5048 ms | 47844 KiB |
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>
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
//#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=2e5+6;
const int INF=1e9;
vector<int> adj[maxn];
int q,n,in[maxn],out[maxn],a[maxn],b[maxn],v[maxn],cur;
string s[maxn];
struct node
{
node* child[2];
int Max,Min;
set<int> s;
node()
{
child[1]=child[0]=NULL;
}
};
node* root=new node();
void add(int x,int val)
{
node* cur=root;
for(int i=30;i>=0;i--)
{
int c=(x>>i)&1;
if(cur->child[c]==NULL) cur->child[c]=new node();
cur=cur->child[c];
cur->s.insert(val);
}
}
int get(int val,int l,int r)
{
node* cur =root;
int ans=0;
for(int i=30;i>=0;i--)
{
int c=(val>>i)&1;
node* kk=cur->child[1^c];
if(kk!=NULL)
{
auto k=lower_bound(kk->s.begin(),kk->s.end(),l);
if(k!=kk->s.end()&&*k<=r)
{
ans+=(1<<i);
cur=cur->child[1^c];
}
else cur=cur->child[c];
}
else cur=cur->child[c];
}
return ans;
}
void dfs(int x)
{
in[x]=++cur;
for(int y:adj[x])
{
dfs(y);
}
out[x]=cur;
}
signed main()
{
if (fopen(taskname".INP","r"))
{
freopen(taskname".INP","r",stdin);
freopen(taskname".OUT","w",stdout);
}
Faster
cin>>q;
n=1;
for(int i=1;i<=q;i++)
{
cin>>s[i]>>a[i]>>b[i];
if(s[i]=="Add")
{
adj[a[i]].push_back(++n);
v[n]=b[i]^v[a[i]];
}
}
dfs(1);
cur=1;
add(v[1],in[1]);
for(int i=1;i<=q;i++)
{
if(s[i]=="Add")
{
++cur;
add(v[cur],in[cur]);
}
else
{
cout<<get(v[a[i]],in[b[i]],out[b[i]])<<"\n";
}
}
}
Compilation message (stderr)
# | 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... |