Submission #1342492

#TimeUsernameProblemLanguageResultExecution timeMemory
1342492vjudge1Klasika (COCI20_klasika)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast, unroll-loops")
#ifdef ONLINE_JUDGE
    #define debug(...) ((void)0)
#else
    #include "debug.h"
#endif
using namespace std;
using ll = long long;
#define endl '\n'

struct Trie{
    struct Node{
        Node *child[2];
        int freq, i;
        Node(){
            child[0] = child[1] = NULL;
            freq = 0;
            i = -1;
        }
    };
    Node *root;
    int bits;
    Trie(int x){
        root = new Node();
        bits = x;
    }
    void insert(ll val, int time){
        Node *current = root;
        for (int i = bits; i >= 0; i--){
            bool bit = (val >> i) & 1;
            if (current->child[bit] == NULL){
                current->child[bit] = new Node();
            }
            current = current->child[bit];
            current->freq++;
            current->i = max(current->i, time);
        }
    }
    ll mxXor(ll val, int l){
        Node *current = root;
        ll ret = 0;
        for (ll i = bits; i >= 0; i--){
            bool bit = (val >> i) & 1;
            if (current->child[bit ^ 1] && current->child[bit ^ 1]->i >= l){
                current = current->child[bit ^ 1];
                ret |= (1 << i);
            }else{
                if(current->child[bit]) current = current->child[bit];
                else assert(0);
            }

        }
        return ret;
    }
};

void SOLVE(){
    int q; cin >> q;
    int n = 1;
    vector<vector<int>> graph(n + 1);
    vector<array<int, 4>> qu(q);
    for(int i = 0; i < q; i++){
        string s; cin >> s;
        int t = (s == "Add" ? 1 : 0);
        if(t == 1){
            int x, y; cin >> x >> y;
            graph[x].push_back(++n);
            graph.push_back(vector<int>());
            qu[i] = {t, x, n, y};
        }else{
            int a, b; cin >> a >> b;
            qu[i] = {t, a, b, -1};
        }
    }

    vector<int> tin(n + 1), tout(n + 1), vertex(n + 1), sz(n + 1, 1), d(n + 1, 1);
    int timer = 0;
    function<int(int, int)> euler =[&](int u, int p){
        tin[u] = ++timer;
        vertex[tin[u]] = u;
        for(auto v : graph[u]) if(v != p){
            d[v] = d[u] + 1;
            sz[u] += euler(v, u);
        }
        tout[u] = timer;
        return sz[u];
    };
    euler(1, -1);

    
    vector<ll> prevxor(n + 1);
    vector<vector<array<ll, 4>>> queries(n + 1);
    int time = 1;
    for(auto &[t, a, b, w] : qu){
        if(t == 1){
            prevxor[b] = prevxor[a] ^ w;
            queries[tin[b]].push_back({1, prevxor[b], tin[b], time++}); // {type, val, L, time}
        }else{
            int val = prevxor[a];
            int L = tin[b], R = tout[b];
            queries[R].push_back({0, val, L, time++}); // {type, val, L, time}
        }   
    }

    Trie tree(30);
    vector<ll> answer(time, -1);
    for(int i = 1; i <= n; i++){
        for(auto &[t, val, L, j] : queries[i]){
            if(t == 1){
                tree.insert(val, L);
            }else{
                answer[j] = tree.mxXor(val, L);
            }
        }
    }
    for(auto & v : answer) if(~v) cout << v << endl;
}
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    // int o_o; cin >> o_o; while(o_o--)
    SOLVE(); return 0;
}

Compilation message (stderr)

klasika.cpp:6:14: fatal error: debug.h: No such file or directory
    6 |     #include "debug.h"
      |              ^~~~~~~~~
compilation terminated.