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;
struct node
{
node * ch[2];
node()
{
ch[0] = ch[1] = NULL;
}
void insert(int x, int b = 30)
{
if(b == -1) return;
bool bit = (1 << b) & x;
if(ch[bit] == NULL)
ch[bit] = new node();
ch[bit] -> insert(x, b - 1);
}
int query(int x, int b = 30)
{
if(b == -1) return 0;
bool bit = (1 << b) & x;
if(ch[!bit] != NULL)
return (1 << b) + ch[!bit] -> query(x, b - 1);
return ch[bit] -> query(x, b - 1);
}
};
const int N = 2005;
node *Tries[N];
int path[N], par[N];
int main()
{
int q;
cin >> q;
int cnt = 1;
Tries[1] = new node();
Tries[1] -> insert(path[1]);
for(int i = 0; i < q; i++)
{
string cmd;
int a, b;
cin >> cmd >> a >> b;
if(cmd == "Query")
{
cout << Tries[b] -> query(path[a]) << endl;
}
else
{
cnt++;
path[cnt] = path[a] ^ b;
if(q > 2000)
Tries[1] -> insert(path[cnt]);
else
{
par[cnt] = a;
Tries[cnt] = new node();
int cur = cnt;
while(cur > 0)
{
Tries[cur] -> insert(path[cnt]);
cur = par[cur];
}
}
}
}
return 0;
}
# | 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... |