답안 #891757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891757 2023-12-24T02:18:13 Z Fucsdeptrai Klasika (COCI20_klasika) C++17
11 / 110
579 ms 524288 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[N];

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

int Get(int id, int x, int y)
{
    Node *p = Trie[id];
    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[u] = new Node();
    for(auto [x, y] : vec[u])
    {
        Add(u, x, y);
    }
    for(auto [xy, id] : que[u])
    {
        auto [x, y] = xy;
        res[id] = Get(u, d[x], 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});
        }
        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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 17756 KB Output is correct
2 Correct 5 ms 19036 KB Output is correct
3 Correct 9 ms 22620 KB Output is correct
4 Correct 13 ms 26080 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 17372 KB Output is correct
8 Correct 5 ms 17500 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 5 ms 17500 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 17756 KB Output is correct
2 Correct 5 ms 19036 KB Output is correct
3 Correct 9 ms 22620 KB Output is correct
4 Correct 13 ms 26080 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 17372 KB Output is correct
8 Correct 5 ms 17500 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 5 ms 17500 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18524 KB Output is correct
13 Correct 63 ms 80212 KB Output is correct
14 Correct 222 ms 251244 KB Output is correct
15 Runtime error 501 ms 524288 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 579 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 17756 KB Output is correct
2 Correct 5 ms 19036 KB Output is correct
3 Correct 9 ms 22620 KB Output is correct
4 Correct 13 ms 26080 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 17372 KB Output is correct
8 Correct 5 ms 17500 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 5 ms 17500 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18524 KB Output is correct
13 Correct 63 ms 80212 KB Output is correct
14 Correct 222 ms 251244 KB Output is correct
15 Runtime error 501 ms 524288 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -