Submission #1330010

#TimeUsernameProblemLanguageResultExecution timeMemory
1330010sashimivssushiKlasika (COCI20_klasika)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define ll long long
#define db double
#define sti string
#define vt vector
#define INF ((int) 1e9)
#define MOD 1000000007
#define BASE 311
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pdd pair<db, db>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << '\n';
#define bit(mask, i) ((mask >> i) & 1)
#define fi first
#define sc second

using namespace std;

const sti name = "";
const int MAXN = 2e5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void file () {
    freopen ((name + ".inp").c_str (), "r", stdin);
    freopen ((name + ".out").c_str (), "w", stdout);
}

vt<int> adj[MAXN + 5];
int d[MAXN + 5], in[MAXN + 5], out[MAXN + 5], timeDFS = 0;

void dfs (int u) {
    in[u] = ++timeDFS;
    for (int& v : adj[u]) {
        d[v] ^= d[u];
        dfs(v);
    }
    out[u] = timeDFS;
}

struct BinaryTrie {
    struct Node {
        int child[2]; unordered_set<int> ins;
        Node () { memset(child, -1, sizeof(child)); }
    };
    vt<Node> nodes;
    int BIT;
    int new_node () {
        nodes.emplace_back();
        return nodes.size() - 1;
    }
    BinaryTrie (int _BIT = 31) {
        BIT = _BIT;
        new_node();
    }
    void insert (int u) {
        int cur = 0;
        for (int j = BIT; j >= 0; --j) {
            int b = bit(d[u], j);
            if (nodes[cur].child[b] == -1)
                nodes[cur].child[b] = new_node();
            cur = nodes[cur].child[b];
            nodes[cur].ins.insert(in[u]);
        }
    }
    int query (int A, int B) {
        int cur = 0, res = 0;
        for (int j = BIT; j >= 0; --j) {
            int b = bit(d[A], j);
            bool ok = false;
            int c = nodes[cur].child[b ^ 1];
            if (c != -1) {
                auto it = nodes[c].ins.lower_bound(in[B]);
                if (it != end(nodes[c].ins) && *it <= out[B])
                    ok = true;
            }
            if (ok) {
                res += (1 << j);
                cur = c;
            }
            else cur = nodes[cur].child[b];
        }
        return res;
    }
};

struct Query {
    char type; int fi, sc;
    Query (char type, int fi, int sc) : 
    type(type), fi(fi), sc(sc) {}
};

int main () {
    ios_base::sync_with_stdio (false);
    cin.tie (nullptr); cout.tie (nullptr);

    vt<Query> queries;
    int q, n = 1; cin >> q;
    while (q--) {
        sti cmd; int fi, sc;
        cin >> cmd >> fi >> sc;
        queries.emplace_back(cmd[0], fi, sc);
        if (cmd[0] == 'A') {
            adj[fi].emplace_back(++n);
            d[n] = sc;
        }
    }
    n = 1; dfs(1);
    BinaryTrie BT;
    for (auto& [type, fi, sc] : queries) {
        if (type == 'A') BT.insert(++n);
        else cout << BT.query(fi, sc) << '\n';
    }

    return 0;
}

Compilation message (stderr)

klasika.cpp: In member function 'int BinaryTrie::query(int, int)':
klasika.cpp:77:40: error: 'class std::unordered_set<int>' has no member named 'lower_bound'
   77 |                 auto it = nodes[c].ins.lower_bound(in[B]);
      |                                        ^~~~~~~~~~~