답안 #846030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846030 2023-09-07T07:07:00 Z vjudge1 Klasika (COCI20_klasika) C++17
110 / 110
2362 ms 465068 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN = 2e5;

#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    #define OPEN freopen(".in", "r", stdin); \
                 freopen(".out", "w", stdout);
#else
    #define OPEN void(23);
#endif

vector <pair <int, int>> adj[MAXN];
int in[MAXN], out[MAXN];

struct Node
{
    set <int> inds;
    Node *l = NULL, *r = NULL;
    Node() {inds.clear();}
};

struct Trie
{
    Node *root;
    Trie() {root = new Node();}

    void add(int x, int ind) {add(x, ind, root);}
    void add(int x, int ind, Node *node, int bit = 32)
    {
        node->inds.emplace(ind);
        if(bit < 0) return;
        if(((x >> bit) & 1))
        {
            if(node->r == NULL) node->r = new Node();
            add(x, ind, node->r, bit -1);
        }
        else
        {
            if(node->l == NULL) node->l = new Node();
            add(x, ind, node->l, bit -1);
        }
    }

    bool check(Node *node, int l, int r)
    {
        return node->inds.lower_bound(l) != node->inds.upper_bound(r);
    }

    int query(int x, int l, int r) {return query(x, l, r, root);}
    int query(int x, int l, int r, Node *node, int bit = 32)
    {
        if(bit < 0) return 0;
        if((x >> bit) & 1)
        {
            if(node->l != NULL && check(node->l, l, r)) return (1 << bit) + query(x, l, r, node->l, bit -1);
            return query(x, l, r, node->r, bit -1);
        }
        else
        {
            if(node->r != NULL && check(node->r, l, r)) return (1 << bit) + query(x, l, r, node->r, bit -1);
            return query(x, l, r, node->l, bit -1);
        }
    }
};

void solve()
{
    int q; cin >> q;
    vector <tuple <string, int, int>> queries(q);
    for(auto &[s, a, b] : queries) cin >> s >> a >> b;

    vector <int> dists(2);
    dists[1] = 0;
    int cnt = 2;
    for(auto &[s, a, b] : queries)
    {
        if(s[0] == 'A')
        {
            adj[a].emplace_back(cnt, b);
            dists.emplace_back(dists[a] ^ b);
            cnt++;
        }
    }

    int timer = 0;
    function <void(int)> dfs = [&](int node) -> void
    {
        in[node] = ++timer;
        for(auto &[child, d] : adj[node])
            dfs(child);

        out[node] = timer;
    };

    dfs(1);

    Trie trie;
    trie.add(0, 1);

    int nw = 2;
    for(auto &[s, a, b] : queries)
    {
        if(s[0] == 'Q')
        {
            cout << trie.query(dists[a], in[b], out[b]) << "\n";
        }
        else
        {
            trie.add(dists[nw], in[nw]);
            nw++;
        }
    }

    return;
}

int32_t main()
{
    OPEN;

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t = 1; //cin >> t;
    while(t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 4 ms 8024 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 3 ms 8536 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 4 ms 8024 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 3 ms 8536 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 5 ms 9816 KB Output is correct
14 Correct 7 ms 10840 KB Output is correct
15 Correct 9 ms 12376 KB Output is correct
16 Correct 8 ms 13400 KB Output is correct
17 Correct 7 ms 9560 KB Output is correct
18 Correct 6 ms 10840 KB Output is correct
19 Correct 9 ms 12120 KB Output is correct
20 Correct 9 ms 13148 KB Output is correct
21 Correct 5 ms 9560 KB Output is correct
22 Correct 6 ms 10840 KB Output is correct
23 Correct 11 ms 12120 KB Output is correct
24 Correct 9 ms 13144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 136696 KB Output is correct
2 Correct 1133 ms 248928 KB Output is correct
3 Correct 1516 ms 356844 KB Output is correct
4 Correct 1873 ms 464840 KB Output is correct
5 Correct 686 ms 133676 KB Output is correct
6 Correct 1129 ms 242876 KB Output is correct
7 Correct 1620 ms 347356 KB Output is correct
8 Correct 2162 ms 452244 KB Output is correct
9 Correct 618 ms 133632 KB Output is correct
10 Correct 1030 ms 244168 KB Output is correct
11 Correct 1481 ms 350384 KB Output is correct
12 Correct 1902 ms 455064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 4 ms 8024 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 3 ms 8536 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 5 ms 9816 KB Output is correct
14 Correct 7 ms 10840 KB Output is correct
15 Correct 9 ms 12376 KB Output is correct
16 Correct 8 ms 13400 KB Output is correct
17 Correct 7 ms 9560 KB Output is correct
18 Correct 6 ms 10840 KB Output is correct
19 Correct 9 ms 12120 KB Output is correct
20 Correct 9 ms 13148 KB Output is correct
21 Correct 5 ms 9560 KB Output is correct
22 Correct 6 ms 10840 KB Output is correct
23 Correct 11 ms 12120 KB Output is correct
24 Correct 9 ms 13144 KB Output is correct
25 Correct 698 ms 136696 KB Output is correct
26 Correct 1133 ms 248928 KB Output is correct
27 Correct 1516 ms 356844 KB Output is correct
28 Correct 1873 ms 464840 KB Output is correct
29 Correct 686 ms 133676 KB Output is correct
30 Correct 1129 ms 242876 KB Output is correct
31 Correct 1620 ms 347356 KB Output is correct
32 Correct 2162 ms 452244 KB Output is correct
33 Correct 618 ms 133632 KB Output is correct
34 Correct 1030 ms 244168 KB Output is correct
35 Correct 1481 ms 350384 KB Output is correct
36 Correct 1902 ms 455064 KB Output is correct
37 Correct 1204 ms 137432 KB Output is correct
38 Correct 1635 ms 248344 KB Output is correct
39 Correct 1946 ms 358892 KB Output is correct
40 Correct 2044 ms 465068 KB Output is correct
41 Correct 1117 ms 133700 KB Output is correct
42 Correct 1698 ms 242360 KB Output is correct
43 Correct 1991 ms 347216 KB Output is correct
44 Correct 2362 ms 451344 KB Output is correct
45 Correct 1234 ms 133640 KB Output is correct
46 Correct 1776 ms 243712 KB Output is correct
47 Correct 2062 ms 348636 KB Output is correct
48 Correct 2102 ms 454680 KB Output is correct