이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int LG = 30;
int q, n = 1, w[N], x[N], y[N];
string t[N];
vector <int> adj[N];
int st[N], ed[N], cnt = 0;
void dfs(int u){
    st[u] = ++ cnt;
    for (int v : adj[u]){
        w[v] ^= w[u];
        dfs(v);
    }
    ed[u] = cnt;
}
struct Node{
    Node *child[2];
    vector <int> idx;
    Node(){
        child[0] = NULL; child[1] = NULL;
        idx = {};
    }
} *root = new Node();
void add(int u){
    Node *p = root;
    for (int i = LG; i >= 0; -- i){
        int b = (w[u] >> i) & 1;
        if (p -> child[b] == NULL) p -> child[b] = new Node();
        p = p -> child[b];
        p -> idx.push_back(st[u]);
    }
}
bool mid(vector <int> &h, int l, int r){
    int it = lower_bound(h.begin(), h.end(), l) - h.begin();
    return it < int(h.size()) && h[it] <= r;
}
int get(int u, int l, int r){
    int ans = 0;
    Node *p = root;
    for (int i = LG; i >= 0; -- i){
        int b = (u >> i) & 1;
        if (p -> child[1 ^ b] != NULL && mid(p -> child[1 ^ b] -> idx, l, r)) {
            ans += (1 << i);
            p = p -> child[1 ^ b];
        }
        else p = p -> child[b];
    }
    return ans;
}
void solve(){
    cin >> q;
    for (int i = 1; i <= q; ++ i){
        cin >> t[i] >> x[i] >> y[i];
        if (t[i] == "Add"){
            ++ n;
            adj[x[i]].push_back(n);
            w[n] = y[i]; x[i] = n;
        }
    }
    dfs(1);
    for (int i = 1; i <= q; ++ i){
        if (t[i] == "Add") add(x[i]);
        else cout << get(w[x[i]], st[y[i]], ed[y[i]]) << '\n';
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    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... |