Submission #891765

# Submission time Handle Problem Language Result Execution time Memory
891765 2023-12-24T03:12:52 Z Fucsdeptrai Klasika (COCI20_klasika) C++17
110 / 110
2084 ms 431976 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 9;
const int Log = 30;

struct Node
{
    Node *c[2];
    set<int> idx;

    Node()
    {
        c[0] = c[1] = NULL;
    }
} *Trie;

int n, m, q, Timer;
int d[N], num[N], tail[N];
vector<pair<int, int>> adj[N];
vector<pair<int, pair<int, int>>> que;

void Dfs(int u = 1, int du = 0)
{
    num[u] = ++Timer;
    d[u] = du;
    for(auto [v, w] : adj[u])
    {
        Dfs(v, du^w);
    }
    tail[u] = Timer;
}

int Get(Node *p, int x, int y)
{
    for(int i = Log;i >= 0;i --)
    {
        bool w = (1<<i)&x;
        if(p->c[w^1] != NULL and (p->c[w^1]->idx.lower_bound(num[y]) != p->c[w^1]->idx.upper_bound(tail[y])))
        {
            x ^= ((w^1) << i);
            p=p->c[w^1];
        }
        else
        {
            x ^= (w<<i);
            p=p->c[w];
        }
    }
    return x;
}

void Add(Node *p, int x, int y)
{
    for(int i = Log;i >= 0;i --)
    {
        bool w = (1<<i)&x;
        if(p->c[w]==NULL) p->c[w] = new Node();
        p=p->c[w];
        p->idx.insert(y);
    }
}

void Solve()
{
    cin>>q;
    ++n;
    while(q--)
    {
        string Type; cin>>Type;
        int x, y; cin >> x >> y;
        if(Type == "Add")
        {
            adj[x].push_back({++n, y});
            que.push_back({0, {n, n}});
        }
        else
        {
            que.push_back({1, {x, y}});
        }
    }

    Dfs();
    Trie = new Node();
    Add(Trie, 0, 1);
    for(auto [Type, xy] : que)
    {
        auto [x, y] = xy;
        if(Type)
        {
            cout << Get(Trie, d[x], y) << '\n';
        }
        else
        {
            Add(Trie, d[x], num[x]);
        }
    }
}

signed main()
{
//	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	int TC = 1;
//	cin>>TC;
    while(TC--)
    {
        Solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 3 ms 7004 KB Output is correct
7 Correct 2 ms 7028 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 3 ms 7180 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 3 ms 7004 KB Output is correct
7 Correct 2 ms 7028 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 3 ms 7180 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 4 ms 8008 KB Output is correct
14 Correct 5 ms 9308 KB Output is correct
15 Correct 7 ms 10588 KB Output is correct
16 Correct 8 ms 11864 KB Output is correct
17 Correct 5 ms 8028 KB Output is correct
18 Correct 5 ms 9308 KB Output is correct
19 Correct 7 ms 10588 KB Output is correct
20 Correct 8 ms 11608 KB Output is correct
21 Correct 5 ms 8028 KB Output is correct
22 Correct 6 ms 9308 KB Output is correct
23 Correct 7 ms 10588 KB Output is correct
24 Correct 8 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 713 ms 123016 KB Output is correct
2 Correct 1052 ms 228092 KB Output is correct
3 Correct 1382 ms 329580 KB Output is correct
4 Correct 1744 ms 429808 KB Output is correct
5 Correct 675 ms 121820 KB Output is correct
6 Correct 1096 ms 225084 KB Output is correct
7 Correct 1513 ms 324316 KB Output is correct
8 Correct 1947 ms 422916 KB Output is correct
9 Correct 635 ms 121592 KB Output is correct
10 Correct 1012 ms 226008 KB Output is correct
11 Correct 1358 ms 326348 KB Output is correct
12 Correct 1644 ms 424992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 3 ms 7004 KB Output is correct
7 Correct 2 ms 7028 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 3 ms 7180 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 4 ms 8008 KB Output is correct
14 Correct 5 ms 9308 KB Output is correct
15 Correct 7 ms 10588 KB Output is correct
16 Correct 8 ms 11864 KB Output is correct
17 Correct 5 ms 8028 KB Output is correct
18 Correct 5 ms 9308 KB Output is correct
19 Correct 7 ms 10588 KB Output is correct
20 Correct 8 ms 11608 KB Output is correct
21 Correct 5 ms 8028 KB Output is correct
22 Correct 6 ms 9308 KB Output is correct
23 Correct 7 ms 10588 KB Output is correct
24 Correct 8 ms 11612 KB Output is correct
25 Correct 713 ms 123016 KB Output is correct
26 Correct 1052 ms 228092 KB Output is correct
27 Correct 1382 ms 329580 KB Output is correct
28 Correct 1744 ms 429808 KB Output is correct
29 Correct 675 ms 121820 KB Output is correct
30 Correct 1096 ms 225084 KB Output is correct
31 Correct 1513 ms 324316 KB Output is correct
32 Correct 1947 ms 422916 KB Output is correct
33 Correct 635 ms 121592 KB Output is correct
34 Correct 1012 ms 226008 KB Output is correct
35 Correct 1358 ms 326348 KB Output is correct
36 Correct 1644 ms 424992 KB Output is correct
37 Correct 1132 ms 125732 KB Output is correct
38 Correct 1617 ms 229996 KB Output is correct
39 Correct 1850 ms 332720 KB Output is correct
40 Correct 2071 ms 431976 KB Output is correct
41 Correct 1108 ms 122444 KB Output is correct
42 Correct 1631 ms 225740 KB Output is correct
43 Correct 1919 ms 324120 KB Output is correct
44 Correct 2084 ms 422580 KB Output is correct
45 Correct 1193 ms 122396 KB Output is correct
46 Correct 1716 ms 226384 KB Output is correct
47 Correct 1985 ms 325248 KB Output is correct
48 Correct 2007 ms 424772 KB Output is correct