Submission #891758

# Submission time Handle Problem Language Result Execution time Memory
891758 2023-12-24T02:24:46 Z Fucsdeptrai Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 28544 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];
    int mn;

    Node()
    {
        c[0] = c[1] = NULL;
        mn = N;
    }
};

int n, m, q, Timer;
int d[N], res[N];
vector<pair<int, int>> adj[N], vec[N];
vector<pair<pair<int, int>, int>> que[N];
Node *Trie;

void Add(int x, int y)
{
    Node *p = Trie;
    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->mn = min(p->mn, y);
    }
}

void Remove(Node *p)
{
    if(p->c[0] != NULL) Remove(p->c[0]);
    if(p->c[1] != NULL) Remove(p->c[1]);
    delete p;
}

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

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

void Merge(int u, int v)
{
    if(vec[u].size() < vec[v].size()) swap(vec[u], vec[v]);
    for(auto x : vec[v]) vec[u].push_back(x);
}

void Dfs1(int u = 1)
{
    vec[u].push_back({d[u], u});
    for(auto [v, w] : adj[u])
    {
        Dfs1(v);
        Merge(u, v);
    }
    Trie = new Node();
    for(auto [x, y] : vec[u])
    {
        Add(x, y);
    }
    for(auto [xy, id] : que[u])
    {
        auto [x, y] = xy;
        res[id] = Get(d[x], y);
    }
    Remove(Trie);
}

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});
        }
        else
        {
            que[y].push_back({{x, n}, ++m});
        }
    }

    Timer = 0;
    Dfs();
    Dfs1();
    for(int i = 1;i <= m; i++)
    {
        cout << res[i] << '\n';
    }
}

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 4 ms 14940 KB Output is correct
2 Correct 7 ms 14940 KB Output is correct
3 Correct 7 ms 14940 KB Output is correct
4 Correct 9 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 3 ms 14960 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 6 ms 15196 KB Output is correct
12 Correct 5 ms 15032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 7 ms 14940 KB Output is correct
3 Correct 7 ms 14940 KB Output is correct
4 Correct 9 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 3 ms 14960 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 6 ms 15196 KB Output is correct
12 Correct 5 ms 15032 KB Output is correct
13 Correct 48 ms 15196 KB Output is correct
14 Correct 192 ms 15648 KB Output is correct
15 Correct 490 ms 15952 KB Output is correct
16 Correct 887 ms 16436 KB Output is correct
17 Correct 7 ms 15192 KB Output is correct
18 Correct 9 ms 15452 KB Output is correct
19 Correct 12 ms 15816 KB Output is correct
20 Correct 14 ms 15964 KB Output is correct
21 Correct 13 ms 15196 KB Output is correct
22 Correct 36 ms 15440 KB Output is correct
23 Correct 84 ms 15696 KB Output is correct
24 Correct 160 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5054 ms 28544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 7 ms 14940 KB Output is correct
3 Correct 7 ms 14940 KB Output is correct
4 Correct 9 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 3 ms 14960 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 6 ms 15196 KB Output is correct
12 Correct 5 ms 15032 KB Output is correct
13 Correct 48 ms 15196 KB Output is correct
14 Correct 192 ms 15648 KB Output is correct
15 Correct 490 ms 15952 KB Output is correct
16 Correct 887 ms 16436 KB Output is correct
17 Correct 7 ms 15192 KB Output is correct
18 Correct 9 ms 15452 KB Output is correct
19 Correct 12 ms 15816 KB Output is correct
20 Correct 14 ms 15964 KB Output is correct
21 Correct 13 ms 15196 KB Output is correct
22 Correct 36 ms 15440 KB Output is correct
23 Correct 84 ms 15696 KB Output is correct
24 Correct 160 ms 16000 KB Output is correct
25 Execution timed out 5054 ms 28544 KB Time limit exceeded
26 Halted 0 ms 0 KB -