답안 #1117563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117563 2024-11-24T02:20:19 Z LonlyR Klasika (COCI20_klasika) C++17
110 / 110
2410 ms 515128 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;
const int maxn = 2e5 + 5;
int q, n = 1, cnt;
int in[maxn], out[maxn], val[maxn];
vector<pair<int,int>> adj[maxn];
tuple<int,int,int> query[maxn];

struct node{
    int c[2];
    set<int> s;
    node()
    {
        c[0] = c[1] = 0;
        s.clear();
    }
};

vector<node> T(1);

void add(int x, int y)
{
    for (int i = 30, cur = 0; i >= 0; i--)
    {
        int nxt = x >> i & 1;
        if (T[cur].c[nxt] == 0) T[cur].c[nxt] = T.size(), T.emplace_back();
        cur = T[cur].c[nxt];
        T[cur].s.emplace(y);
    }
}

bool check(set<int> &x, int y)
{
    auto it = x.lower_bound(in[y]);
    return it != x.end() && (*it) <= out[y];
}

int qry(int X, int y, int cur = 0, int bit = 30)
{
    if (bit == -1) return 0;
    int nxt = X >> bit & 1;
    if (T[cur].c[nxt ^ 1] && check(T[T[cur].c[nxt ^ 1]].s, y))
        return (1ll << bit) + qry(X, y, T[cur].c[nxt ^ 1], bit - 1);
    return qry(X, y, T[cur].c[nxt], bit - 1);
}

void dfs(int x = 1, int p = 0)
{
    in[x] = ++cnt;
    for (auto [i, w] : adj[x]) if (i != p)
        val[i] = val[x] ^ w,
        dfs(i, x);
    out[x] = cnt;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    cin >> q;
    for (int i = 1; i <= q; i++)
    {
        string s; int x, y;
        cin >> s >> x >> y;
        if (s[0] == 'A')
            adj[x].emplace_back(++n, y), query[i] = {1, n, y};
        else query[i] = {0, x, y};
    }
    dfs();
    add(0, 1);
    for (int i = 1; i <= q; i++)
    {
        auto [type, x, y] = query[i];
        if (type == 1)
            add(val[x], in[x]);
        else cout << qry(val[x], y) << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9040 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 9040 KB Output is correct
8 Correct 2 ms 9040 KB Output is correct
9 Correct 2 ms 8784 KB Output is correct
10 Correct 2 ms 9208 KB Output is correct
11 Correct 2 ms 9040 KB Output is correct
12 Correct 3 ms 9040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9040 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 9040 KB Output is correct
8 Correct 2 ms 9040 KB Output is correct
9 Correct 2 ms 8784 KB Output is correct
10 Correct 2 ms 9208 KB Output is correct
11 Correct 2 ms 9040 KB Output is correct
12 Correct 3 ms 9040 KB Output is correct
13 Correct 5 ms 10476 KB Output is correct
14 Correct 6 ms 12864 KB Output is correct
15 Correct 8 ms 12860 KB Output is correct
16 Correct 9 ms 17344 KB Output is correct
17 Correct 5 ms 10308 KB Output is correct
18 Correct 8 ms 12864 KB Output is correct
19 Correct 7 ms 12884 KB Output is correct
20 Correct 8 ms 13252 KB Output is correct
21 Correct 5 ms 10312 KB Output is correct
22 Correct 7 ms 12880 KB Output is correct
23 Correct 8 ms 12996 KB Output is correct
24 Correct 9 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 478 ms 132664 KB Output is correct
2 Correct 898 ms 258904 KB Output is correct
3 Correct 1270 ms 307960 KB Output is correct
4 Correct 1786 ms 514844 KB Output is correct
5 Correct 480 ms 133528 KB Output is correct
6 Correct 1113 ms 254864 KB Output is correct
7 Correct 1621 ms 304232 KB Output is correct
8 Correct 2272 ms 504424 KB Output is correct
9 Correct 574 ms 133908 KB Output is correct
10 Correct 1016 ms 253524 KB Output is correct
11 Correct 1394 ms 306184 KB Output is correct
12 Correct 2138 ms 505748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9040 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 9040 KB Output is correct
8 Correct 2 ms 9040 KB Output is correct
9 Correct 2 ms 8784 KB Output is correct
10 Correct 2 ms 9208 KB Output is correct
11 Correct 2 ms 9040 KB Output is correct
12 Correct 3 ms 9040 KB Output is correct
13 Correct 5 ms 10476 KB Output is correct
14 Correct 6 ms 12864 KB Output is correct
15 Correct 8 ms 12860 KB Output is correct
16 Correct 9 ms 17344 KB Output is correct
17 Correct 5 ms 10308 KB Output is correct
18 Correct 8 ms 12864 KB Output is correct
19 Correct 7 ms 12884 KB Output is correct
20 Correct 8 ms 13252 KB Output is correct
21 Correct 5 ms 10312 KB Output is correct
22 Correct 7 ms 12880 KB Output is correct
23 Correct 8 ms 12996 KB Output is correct
24 Correct 9 ms 12996 KB Output is correct
25 Correct 478 ms 132664 KB Output is correct
26 Correct 898 ms 258904 KB Output is correct
27 Correct 1270 ms 307960 KB Output is correct
28 Correct 1786 ms 514844 KB Output is correct
29 Correct 480 ms 133528 KB Output is correct
30 Correct 1113 ms 254864 KB Output is correct
31 Correct 1621 ms 304232 KB Output is correct
32 Correct 2272 ms 504424 KB Output is correct
33 Correct 574 ms 133908 KB Output is correct
34 Correct 1016 ms 253524 KB Output is correct
35 Correct 1394 ms 306184 KB Output is correct
36 Correct 2138 ms 505748 KB Output is correct
37 Correct 844 ms 136232 KB Output is correct
38 Correct 1257 ms 259344 KB Output is correct
39 Correct 1619 ms 311940 KB Output is correct
40 Correct 2136 ms 515128 KB Output is correct
41 Correct 905 ms 134036 KB Output is correct
42 Correct 1531 ms 253072 KB Output is correct
43 Correct 1979 ms 304528 KB Output is correct
44 Correct 2410 ms 506596 KB Output is correct
45 Correct 911 ms 134420 KB Output is correct
46 Correct 1419 ms 253904 KB Output is correct
47 Correct 1742 ms 305312 KB Output is correct
48 Correct 2192 ms 505920 KB Output is correct