답안 #889568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889568 2023-12-20T02:48:39 Z dimashhh Klasika (COCI20_klasika) C++17
110 / 110
2107 ms 443180 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1, MOD = 998244353,b = 30;
typedef long long ll;
vector<array<int,3>> qr;
int q,tin[N],tout[N],n = 1,d[N],timer = 0;
vector<pair<int,int>> g[N];
void dfs(int v){
    tin[v] = ++timer;
    for(auto [to,w]:g[v]){
        d[to] = (d[v] ^ w);
        dfs(to);
    }
    tout[v] =timer;
}
struct node{
    node *next[2];
    set<int> st;
    node(){
        for(int i = 0;i < 2;i++){
            next[i] = nullptr;
        }
    }
};
node *root = new node();
void add(int tadd,int val){
    node *cur = root;
    cur->st.insert(tadd);
    for(int i = b;i >= 0;i--){
        int nv = ((val >> i) & 1);
        
        if(!cur->next[nv])
            cur->next[nv] = new node();
        cur = cur->next[nv];
        cur->st.insert(tadd);
    }
}
int get(int val,int l,int r){
    node *cur = root;
    if(cur->st.empty()) return 0;
    int ret = 0;
    for(int i = b;i >= 0;i--){
        int nd = ((val >> i) & 1);
        nd ^= 1;
        bool ok = false;
        if(cur->next[nd]){
            auto it = cur->next[nd]->st.lower_bound(l);
            if(it != cur->next[nd]->st.end() && *it <= r){
                ok = 1;
            }
        }
        if(ok){
            ret += (1ll << i);
            cur = cur->next[nd];
        }else{
            cur = cur->next[!nd];
        }
    }
    return ret;
}
void test(){
    cin >> q;
    for(int i = 1;i <= q;i++){
        string tp;
        cin >> tp;
        if(tp[0] == 'A'){
            ++n;
            int x,y;
            cin >> x >> y;
            g[x].push_back({n,y});
            qr.push_back({1,n,y});
        }else{
            int x,y;
            cin >> x >> y;
            qr.push_back({2,x,y});
        }
    }
    dfs(1);
    add(tin[1],0);
    for(auto i:qr){
        if(i[0] == 1){
            add(tin[i[1]],d[i[1]]);
            // cout << tin[i[1]] << ' ' << d[i[1]] << "x\n";
        }else{
            // cout << d[i[1]] << ' ' << tin[i[2]] << ' ' << tout[i[2]] << '\n';
            cout << get(d[i[1]],tin[i[2]],tout[i[2]]) << '\n';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1; // cin >> T;
    while (T--)
        test();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11356 KB Output is correct
5 Correct 2 ms 10884 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11148 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 3 ms 11100 KB Output is correct
12 Correct 3 ms 11356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11356 KB Output is correct
5 Correct 2 ms 10884 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11148 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 3 ms 11100 KB Output is correct
12 Correct 3 ms 11356 KB Output is correct
13 Correct 4 ms 12176 KB Output is correct
14 Correct 5 ms 13412 KB Output is correct
15 Correct 7 ms 14924 KB Output is correct
16 Correct 8 ms 16040 KB Output is correct
17 Correct 4 ms 12124 KB Output is correct
18 Correct 6 ms 13400 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 9 ms 15812 KB Output is correct
21 Correct 5 ms 12124 KB Output is correct
22 Correct 6 ms 13540 KB Output is correct
23 Correct 7 ms 14628 KB Output is correct
24 Correct 8 ms 15768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 508 ms 130144 KB Output is correct
2 Correct 864 ms 236708 KB Output is correct
3 Correct 1206 ms 339196 KB Output is correct
4 Correct 1607 ms 441952 KB Output is correct
5 Correct 550 ms 127584 KB Output is correct
6 Correct 964 ms 232520 KB Output is correct
7 Correct 1390 ms 332964 KB Output is correct
8 Correct 1881 ms 433336 KB Output is correct
9 Correct 495 ms 127244 KB Output is correct
10 Correct 877 ms 233324 KB Output is correct
11 Correct 1221 ms 336552 KB Output is correct
12 Correct 1594 ms 435308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11356 KB Output is correct
5 Correct 2 ms 10884 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11148 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 3 ms 11100 KB Output is correct
12 Correct 3 ms 11356 KB Output is correct
13 Correct 4 ms 12176 KB Output is correct
14 Correct 5 ms 13412 KB Output is correct
15 Correct 7 ms 14924 KB Output is correct
16 Correct 8 ms 16040 KB Output is correct
17 Correct 4 ms 12124 KB Output is correct
18 Correct 6 ms 13400 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 9 ms 15812 KB Output is correct
21 Correct 5 ms 12124 KB Output is correct
22 Correct 6 ms 13540 KB Output is correct
23 Correct 7 ms 14628 KB Output is correct
24 Correct 8 ms 15768 KB Output is correct
25 Correct 508 ms 130144 KB Output is correct
26 Correct 864 ms 236708 KB Output is correct
27 Correct 1206 ms 339196 KB Output is correct
28 Correct 1607 ms 441952 KB Output is correct
29 Correct 550 ms 127584 KB Output is correct
30 Correct 964 ms 232520 KB Output is correct
31 Correct 1390 ms 332964 KB Output is correct
32 Correct 1881 ms 433336 KB Output is correct
33 Correct 495 ms 127244 KB Output is correct
34 Correct 877 ms 233324 KB Output is correct
35 Correct 1221 ms 336552 KB Output is correct
36 Correct 1594 ms 435308 KB Output is correct
37 Correct 878 ms 130976 KB Output is correct
38 Correct 1357 ms 237572 KB Output is correct
39 Correct 1607 ms 342092 KB Output is correct
40 Correct 1771 ms 443180 KB Output is correct
41 Correct 965 ms 128316 KB Output is correct
42 Correct 1479 ms 232188 KB Output is correct
43 Correct 1815 ms 332772 KB Output is correct
44 Correct 2107 ms 431504 KB Output is correct
45 Correct 1037 ms 126568 KB Output is correct
46 Correct 1486 ms 232388 KB Output is correct
47 Correct 1765 ms 333008 KB Output is correct
48 Correct 1907 ms 432432 KB Output is correct