답안 #1088883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088883 2024-09-15T12:23:34 Z vladilius Klasika (COCI20_klasika) C++17
110 / 110
2616 ms 487612 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define arr3 array<int, 3>
const int lg = 31;

struct TR{
    struct node{
        set<int> all;
        int nt[2];
        node(){
            nt[0] = nt[1] = 0;
        }
    };
    vector<node> t;
    int cc;
    void init(){
        t.pb({});
        t.pb({});
        cc = 1;
    }
    vector<int> :: iterator it;
    void add(int x, int p){
        int v = 1;
        for (int i = lg; i >= 0; i--){
            bool bit = (x >> i) & 1;
            if (!t[v].nt[bit]){
                t[v].nt[bit] = ++cc;
                t.pb({});
            }
            v = t[v].nt[bit];
            t[v].all.insert(p);
        }
    }
    int get(int l, int r, int x){
        int out = 0, v = 1;
        for (int i = lg; i >= 0; i--){
            bool bit = (x >> i) & 1;
            int k = t[v].nt[!bit];
            auto it = t[k].all.lower_bound(l);
            if (it != t[k].all.end() && (*it) <= r){
                v = k;
                out += (1 << i);
                continue;
            }
            v = t[v].nt[bit];
        }
        return out;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int q, cc = 1; cin>>q;
    vector<arr3> qs;
    vector<pii> g[q + 1];
    for (int i = 1; i <= q; i++){
        string type; int x, y; cin>>type>>x>>y;
        if (type[0] == 'A'){
            cc++;
            g[x].pb({cc, y});
            qs.pb({0, x, cc});
        }
        else {
            qs.pb({1, x, y});
        }
    }
    int n = cc;
    vector<int> tin(n + 1), tout(n + 1), d(n + 1);
    int timer = 0;
    function<void(int)> fill = [&](int v){
        tin[v] = ++timer;
        for (auto [i, w]: g[v]){
            d[i] = d[v] ^ w;
            fill(i);
        }
        tout[v] = timer;
    };
    fill(1);

    TR T; T.init();
    T.add(0, 1);
    for (auto [type, x, y]: qs){
        if (!type){
            T.add(d[y], tin[y]);
        }
        else {
            cout<<T.get(tin[y], tout[y], d[x])<<"\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 5 ms 1912 KB Output is correct
14 Correct 5 ms 3508 KB Output is correct
15 Correct 5 ms 3748 KB Output is correct
16 Correct 9 ms 6680 KB Output is correct
17 Correct 3 ms 1912 KB Output is correct
18 Correct 4 ms 3508 KB Output is correct
19 Correct 5 ms 3632 KB Output is correct
20 Correct 6 ms 4656 KB Output is correct
21 Correct 3 ms 1912 KB Output is correct
22 Correct 4 ms 3508 KB Output is correct
23 Correct 6 ms 3632 KB Output is correct
24 Correct 6 ms 4656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 526 ms 122800 KB Output is correct
2 Correct 1051 ms 241276 KB Output is correct
3 Correct 1491 ms 299024 KB Output is correct
4 Correct 2123 ms 487312 KB Output is correct
5 Correct 588 ms 119280 KB Output is correct
6 Correct 1267 ms 233848 KB Output is correct
7 Correct 1673 ms 288748 KB Output is correct
8 Correct 2371 ms 472728 KB Output is correct
9 Correct 551 ms 119864 KB Output is correct
10 Correct 1045 ms 235224 KB Output is correct
11 Correct 1594 ms 291944 KB Output is correct
12 Correct 2061 ms 475344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 5 ms 1912 KB Output is correct
14 Correct 5 ms 3508 KB Output is correct
15 Correct 5 ms 3748 KB Output is correct
16 Correct 9 ms 6680 KB Output is correct
17 Correct 3 ms 1912 KB Output is correct
18 Correct 4 ms 3508 KB Output is correct
19 Correct 5 ms 3632 KB Output is correct
20 Correct 6 ms 4656 KB Output is correct
21 Correct 3 ms 1912 KB Output is correct
22 Correct 4 ms 3508 KB Output is correct
23 Correct 6 ms 3632 KB Output is correct
24 Correct 6 ms 4656 KB Output is correct
25 Correct 526 ms 122800 KB Output is correct
26 Correct 1051 ms 241276 KB Output is correct
27 Correct 1491 ms 299024 KB Output is correct
28 Correct 2123 ms 487312 KB Output is correct
29 Correct 588 ms 119280 KB Output is correct
30 Correct 1267 ms 233848 KB Output is correct
31 Correct 1673 ms 288748 KB Output is correct
32 Correct 2371 ms 472728 KB Output is correct
33 Correct 551 ms 119864 KB Output is correct
34 Correct 1045 ms 235224 KB Output is correct
35 Correct 1594 ms 291944 KB Output is correct
36 Correct 2061 ms 475344 KB Output is correct
37 Correct 795 ms 123312 KB Output is correct
38 Correct 1388 ms 241640 KB Output is correct
39 Correct 1851 ms 301456 KB Output is correct
40 Correct 2350 ms 487612 KB Output is correct
41 Correct 1010 ms 119712 KB Output is correct
42 Correct 1676 ms 234404 KB Output is correct
43 Correct 2104 ms 289044 KB Output is correct
44 Correct 2616 ms 473032 KB Output is correct
45 Correct 972 ms 120216 KB Output is correct
46 Correct 1668 ms 235684 KB Output is correct
47 Correct 2019 ms 290568 KB Output is correct
48 Correct 2436 ms 475396 KB Output is correct