#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define arr3 array<int, 3>
const int lg = 31;
struct TR{
struct node{
set<int> all;
int nt[2];
node(){
nt[0] = nt[1] = 0;
}
};
vector<node> t;
int cc;
void init(){
t.pb({});
t.pb({});
cc = 1;
}
vector<int> :: iterator it;
void add(int x, int p){
int v = 1;
for (int i = lg; i >= 0; i--){
bool bit = (x >> i) & 1;
if (!t[v].nt[bit]){
t[v].nt[bit] = ++cc;
t.pb({});
}
v = t[v].nt[bit];
t[v].all.insert(p);
}
}
int get(int l, int r, int x){
int out = 0, v = 1;
for (int i = lg; i >= 0; i--){
bool bit = (x >> i) & 1;
int k = t[v].nt[!bit];
if (k > 0){
auto it = t[k].all.lower_bound(l);
if (it != t[k].all.end() && (*it) <= r){
v = k;
out += (1 << i);
continue;
}
}
v = t[v].nt[bit];
}
return out;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, cc = 1; cin>>q;
vector<arr3> qs;
vector<pii> g[q + 1];
bool ind = 1;
for (int i = 1; i <= q; i++){
string type; int x, y; cin>>type>>x>>y;
if (type[0] == 'A'){
cc++;
g[x].pb({cc, y});
qs.pb({0, x, cc});
}
else {
if (y != 1) ind = 0;
qs.pb({1, x, y});
}
}
int n = cc;
vector<int> tin(n + 1), tout(n + 1), d(n + 1);
int timer = 0;
function<void(int)> fill = [&](int v){
tin[v] = ++timer;
for (auto [i, w]: g[v]){
d[i] = d[v] ^ w;
fill(i);
}
tout[v] = timer;
};
fill(1);
TR T; T.init();
for (auto [type, x, y]: qs){
if (!type){
T.add(d[y], tin[y]);
}
else {
cout<<T.get(tin[y], tout[y], d[x])<<"\n";
}
}
}
Compilation message
klasika.cpp: In function 'int main()':
klasika.cpp:66:10: warning: variable 'ind' set but not used [-Wunused-but-set-variable]
66 | bool ind = 1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
537 ms |
122796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |