#include<bits/stdc++.h>
using namespace std;
struct node
{
node * ch[2];
node()
{
ch[0] = ch[1] = NULL;
}
void insert(int x, int b = 31)
{
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 = 31)
{
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(0);
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]);
}
else
{
cnt++;
path[cnt] = path[a] ^ b;
if(q > 2000)
Tries[1] -> insert(path[cnt]);
else
{
par[cnt] = a;
Tries[cnt] = new node();
Tries[cnt] -> insert(0);
int cur = cnt;
while(cur > 0)
{
Tries[cur] -> insert(path[cnt]);
cur = par[cur];
}
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
3420 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |