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 = 2e5+5, M = 2000 + 10;
node *Tries[1];
int path[N], par[M];
vector<int> sub[M];
int main()
{
int q;
cin >> q;
int cnt = 1;
Tries[1] = new node();
Tries[1] -> insert(path[1]);
sub[1].push_back(1);
for(int i = 0; i < q; i++)
{
string cmd;
int a, b;
cin >> cmd >> a >> b;
if(cmd == "Query")
{
if(q > 2000)
cout << Tries[b] -> query(path[a]) << endl;
else
{
int ans = 0;
for(int i : sub[b])
ans = max(ans, path[i] ^ path[a]);
cout << ans << endl;
}
}
else
{
cnt++;
path[cnt] = path[a] ^ b;
if(q > 2000)
Tries[1] -> insert(path[cnt]);
else
{
par[cnt] = a;
int cur = cnt;
while(cur > 0)
{
sub[cur].push_back(cnt);
cur = par[cur];
}
}
}
}
return 0;
}
Compilation message (stderr)
klasika.cpp: In function 'int main()':
klasika.cpp:41:10: warning: array subscript 1 is above array bounds of 'node* [1]' [-Warray-bounds]
41 | Tries[1] = new node();
| ~~~~~~~^
klasika.cpp:32:7: note: while referencing 'Tries'
32 | node *Tries[1];
| ^~~~~
klasika.cpp:66:13: warning: array subscript 1 is above array bounds of 'node* [1]' [-Warray-bounds]
66 | Tries[1] -> insert(path[cnt]);
| ~~~~~~~^
klasika.cpp:32:7: note: while referencing 'Tries'
32 | node *Tries[1];
| ^~~~~
# | 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... |