답안 #857101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857101 2023-10-05T11:32:42 Z Jethro Klasika (COCI20_klasika) C++14
33 / 110
598 ms 524288 KB
//Writed by: Jethro_
//----------------------
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

const int N = 4e6 + 10;
int n, node = 1, i, root, val, in[N], out[N], cnt = 0, Xor[N], LG = 31, child[N][2], cnt2 = 0;
vector<pair<int, int>> a[N];
set<int> save[N];
pair<int, int> query[N];
string type[N];

void add() {
    cin >> n;
    for(i = 1; i <= n; ++i) {
        cin >> type[i];
        if(type[i] == "Add") {
            cin >> root >> val;
            a[++node].push_back({root, val});
            a[root].push_back({node, val});
            
            query[i] = {node, node};
            
        }else {
            cin >> root >> val;
            query[i] = {root, val};
        }
    }
}
void dfs(int u, int p) {
    in[u] = ++cnt;
    for(auto [v, w] : a[u]) {
        if(v == p) continue;
        Xor[v] = Xor[u] ^ w;
        dfs(v, u);
    }

    out[u] = cnt;
}
void ADD(int s, int id) {
    int u = 0;

    for(int i = LG; i >= 0; --i) {
        int k = (s >> i) & 1;
        if(child[u][k] == -1) {
            child[u][k] = ++cnt2;
        }
        u = child[u][k];
        save[u].insert(in[id]);
    }
}
void get(int s, int l, int r) {
    int u = 0, res = 0;
    for(int i = LG; i >= 0; --i) {
        int k = (s >> i) & 1, t = child[u][k ^ 1];
        if(t != -1){
            auto x = save[t].lower_bound(l);
            if(x != save[t].end() && (*x) <= r) {
                u = t;
                res += (1 << i);
            }else {
               u = child[u][k];
            }
        }else {
            u = child[u][k];
        }
    }
    cout << res << '\n';
}
void solve() {

    memset(child, -1, sizeof child);
    dfs(1, 0);
    ADD(0, 1);
    
    for(i = 1; i <= n; ++i) {
        auto [x, y] = query[i];
        if(type[i] == "Add") {
            ADD(Xor[x], y);
        }else {
            int now = Xor[x];
            get(now, in[y], out[y]);
        }
    }
}
int main() {

    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    add();
    solve();

}

Compilation message

klasika.cpp: In function 'void dfs(int, int)':
klasika.cpp:35:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |     for(auto [v, w] : a[u]) {
      |              ^
klasika.cpp: In function 'void solve()':
klasika.cpp:80:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |         auto [x, y] = query[i];
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 441784 KB Output is correct
2 Correct 85 ms 441672 KB Output is correct
3 Correct 85 ms 441988 KB Output is correct
4 Correct 83 ms 441896 KB Output is correct
5 Correct 81 ms 441684 KB Output is correct
6 Correct 83 ms 441736 KB Output is correct
7 Correct 85 ms 441940 KB Output is correct
8 Correct 85 ms 441884 KB Output is correct
9 Correct 81 ms 441680 KB Output is correct
10 Correct 81 ms 441728 KB Output is correct
11 Correct 82 ms 441792 KB Output is correct
12 Correct 83 ms 441936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 441784 KB Output is correct
2 Correct 85 ms 441672 KB Output is correct
3 Correct 85 ms 441988 KB Output is correct
4 Correct 83 ms 441896 KB Output is correct
5 Correct 81 ms 441684 KB Output is correct
6 Correct 83 ms 441736 KB Output is correct
7 Correct 85 ms 441940 KB Output is correct
8 Correct 85 ms 441884 KB Output is correct
9 Correct 81 ms 441680 KB Output is correct
10 Correct 81 ms 441728 KB Output is correct
11 Correct 82 ms 441792 KB Output is correct
12 Correct 83 ms 441936 KB Output is correct
13 Correct 85 ms 442384 KB Output is correct
14 Correct 86 ms 443032 KB Output is correct
15 Correct 86 ms 443728 KB Output is correct
16 Correct 87 ms 444120 KB Output is correct
17 Correct 85 ms 442436 KB Output is correct
18 Correct 87 ms 442964 KB Output is correct
19 Correct 84 ms 443480 KB Output is correct
20 Correct 91 ms 444240 KB Output is correct
21 Correct 84 ms 442284 KB Output is correct
22 Correct 89 ms 442952 KB Output is correct
23 Correct 85 ms 443472 KB Output is correct
24 Correct 88 ms 444268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 598 ms 509172 KB Output is correct
2 Runtime error 434 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 441784 KB Output is correct
2 Correct 85 ms 441672 KB Output is correct
3 Correct 85 ms 441988 KB Output is correct
4 Correct 83 ms 441896 KB Output is correct
5 Correct 81 ms 441684 KB Output is correct
6 Correct 83 ms 441736 KB Output is correct
7 Correct 85 ms 441940 KB Output is correct
8 Correct 85 ms 441884 KB Output is correct
9 Correct 81 ms 441680 KB Output is correct
10 Correct 81 ms 441728 KB Output is correct
11 Correct 82 ms 441792 KB Output is correct
12 Correct 83 ms 441936 KB Output is correct
13 Correct 85 ms 442384 KB Output is correct
14 Correct 86 ms 443032 KB Output is correct
15 Correct 86 ms 443728 KB Output is correct
16 Correct 87 ms 444120 KB Output is correct
17 Correct 85 ms 442436 KB Output is correct
18 Correct 87 ms 442964 KB Output is correct
19 Correct 84 ms 443480 KB Output is correct
20 Correct 91 ms 444240 KB Output is correct
21 Correct 84 ms 442284 KB Output is correct
22 Correct 89 ms 442952 KB Output is correct
23 Correct 85 ms 443472 KB Output is correct
24 Correct 88 ms 444268 KB Output is correct
25 Correct 598 ms 509172 KB Output is correct
26 Runtime error 434 ms 524288 KB Execution killed with signal 9
27 Halted 0 ms 0 KB -