답안 #596946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596946 2022-07-15T09:48:55 Z tht2005 Klasika (COCI20_klasika) C++17
110 / 110
407 ms 187784 KB
#include <bits/stdc++.h>

using namespace std;

#define L 30
#define Q 200005

struct node_t {
    int sz, val;
    node_t* c[2];
    node_t(int vv = Q) : sz(0), val(vv) {
        c[0] = c[1] = NULL;
    }
};
void insert(node_t* p, int x, int val) {
    for(int i = L; i--; ) {
        int e = x >> i & 1;
        if(p->c[e] == NULL) {
            p->c[e] = new node_t(val);
        }
        p = p->c[e];
        ++p->sz;
    }
}
int query(node_t* p, int x, int val) {
    int ret = 0;
    for(int i = L; i--; ) {
        int e = (x >> i & 1) ^ 1;
        if(p->c[e] && p->c[e]->val < val) {
            ret |= 1 << i;
        }
        else {
            e ^= 1;
        }
        p = p->c[e];
    }
    return ret;
}
node_t* merge(node_t* a, node_t* b) {
    if(!a || !b) {
        return a ? a : b;
    }
    if(b->sz < a->sz) {
        swap(a, b);
    }
    a->sz += (b->c[0] ? b->c[0]->sz : 0) + (b->c[1] ? b->c[1]->sz : 0);
    a->val = min(a->val, b->val);
    a->c[0] = merge(a->c[0], b->c[0]);
    a->c[1] = merge(a->c[1], b->c[1]);
    return a;
}

int n = 1, s[Q], res[Q];
node_t* rt[Q];
vector<int> aj[Q];
vector<pair<int, int>> queries[Q];

void dfs(int v) {
    for(int u : aj[v]) {
        dfs(u);
        rt[v] = merge(rt[v], rt[u]);
    }
    for(const auto& [u, i] : queries[v]) {
        res[i] = query(rt[v], s[u], i);
    }
}

int main() {
    int q;
    scanf("%d", &q);
    rt[1] = new node_t();
    insert(rt[1], 0, 0);
    for(int i = 1; i <= q; ++i) {
        char o;
        int x, y;
        scanf(" %c%*s %d %d", &o, &x, &y);
        if(o == 'A') {
            ++n;
            aj[x].push_back(n);
            s[n] = s[x] ^ y;
            rt[n] = new node_t();
            insert(rt[n], s[n], i);
            res[i] = -1;
        }
        else {
            queries[y].emplace_back(x, i);
        }
    }
    dfs(1);
    for(int i = 1; i <= q; ++i) {
        if(res[i] != -1) {
            printf("%d\n", res[i]);
        }
    }
    return 0;
}

Compilation message

klasika.cpp: In function 'int main()':
klasika.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
klasika.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         scanf(" %c%*s %d %d", &o, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9832 KB Output is correct
4 Correct 6 ms 9772 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9796 KB Output is correct
7 Correct 5 ms 9828 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 5 ms 9704 KB Output is correct
11 Correct 5 ms 9812 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9832 KB Output is correct
4 Correct 6 ms 9772 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9796 KB Output is correct
7 Correct 5 ms 9828 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 5 ms 9704 KB Output is correct
11 Correct 5 ms 9812 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 8 ms 10196 KB Output is correct
14 Correct 8 ms 10664 KB Output is correct
15 Correct 8 ms 11000 KB Output is correct
16 Correct 8 ms 11476 KB Output is correct
17 Correct 7 ms 10156 KB Output is correct
18 Correct 7 ms 10580 KB Output is correct
19 Correct 8 ms 10868 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 6 ms 10100 KB Output is correct
22 Correct 7 ms 10488 KB Output is correct
23 Correct 8 ms 11000 KB Output is correct
24 Correct 9 ms 11348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 59132 KB Output is correct
2 Correct 285 ms 101944 KB Output is correct
3 Correct 312 ms 144056 KB Output is correct
4 Correct 355 ms 186796 KB Output is correct
5 Correct 204 ms 56068 KB Output is correct
6 Correct 294 ms 96000 KB Output is correct
7 Correct 331 ms 134956 KB Output is correct
8 Correct 407 ms 174704 KB Output is correct
9 Correct 197 ms 56352 KB Output is correct
10 Correct 260 ms 97248 KB Output is correct
11 Correct 339 ms 137228 KB Output is correct
12 Correct 365 ms 177080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9832 KB Output is correct
4 Correct 6 ms 9772 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9796 KB Output is correct
7 Correct 5 ms 9828 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 5 ms 9704 KB Output is correct
11 Correct 5 ms 9812 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 8 ms 10196 KB Output is correct
14 Correct 8 ms 10664 KB Output is correct
15 Correct 8 ms 11000 KB Output is correct
16 Correct 8 ms 11476 KB Output is correct
17 Correct 7 ms 10156 KB Output is correct
18 Correct 7 ms 10580 KB Output is correct
19 Correct 8 ms 10868 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 6 ms 10100 KB Output is correct
22 Correct 7 ms 10488 KB Output is correct
23 Correct 8 ms 11000 KB Output is correct
24 Correct 9 ms 11348 KB Output is correct
25 Correct 202 ms 59132 KB Output is correct
26 Correct 285 ms 101944 KB Output is correct
27 Correct 312 ms 144056 KB Output is correct
28 Correct 355 ms 186796 KB Output is correct
29 Correct 204 ms 56068 KB Output is correct
30 Correct 294 ms 96000 KB Output is correct
31 Correct 331 ms 134956 KB Output is correct
32 Correct 407 ms 174704 KB Output is correct
33 Correct 197 ms 56352 KB Output is correct
34 Correct 260 ms 97248 KB Output is correct
35 Correct 339 ms 137228 KB Output is correct
36 Correct 365 ms 177080 KB Output is correct
37 Correct 246 ms 60720 KB Output is correct
38 Correct 294 ms 103348 KB Output is correct
39 Correct 349 ms 146208 KB Output is correct
40 Correct 387 ms 187784 KB Output is correct
41 Correct 214 ms 57540 KB Output is correct
42 Correct 282 ms 97216 KB Output is correct
43 Correct 368 ms 136196 KB Output is correct
44 Correct 407 ms 175168 KB Output is correct
45 Correct 201 ms 57804 KB Output is correct
46 Correct 278 ms 98380 KB Output is correct
47 Correct 322 ms 137880 KB Output is correct
48 Correct 374 ms 177916 KB Output is correct