답안 #223284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223284 2020-04-15T06:45:10 Z lyc Klasika (COCI20_klasika) C++14
33 / 110
2955 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int MX_Q = 2e5+5;
const int MX_N = 2e5+5;

int Q;
struct Query { int t, x, y; } query[MX_Q]; // 0 for add, 1 for query

int N;
vector<pair<int,int>> al[MX_N];
int dt, pre[MX_N], pst[MX_N], dist[MX_N];

void dfs(int u) {
    pre[u] = ++dt;
    for (auto v : al[u]) {
        dist[v.first] = dist[u] ^ v.second;
        dfs(v.first);
    }
    pst[u] = dt;
}

#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct node {
    pbds_set<int> v;
    int depth, bit;
    node *l, *r;

    node(int depth, int bit): depth(depth), bit(bit), l(NULL), r(NULL) {}

    bool createChildren() {
        if (l != NULL) return 0;
        l = new node(depth-1, 0);
        r = new node(depth-1, 1);
        return 1;
    }

    void update(int bm, int x) {
        //if (depth < 5) cout << "Updating node " << depth << " " << bit << " :: " << bm << " " << x << endl;
        v.insert(x);
        if (depth == 0) return;
        createChildren();
        if ((bm&(1<<(depth-1))) == 0) l->update(bm,x);
        else r->update(bm,x);
    }

    bool contains(int x, int y) {
        return v.order_of_key(y+1) - v.order_of_key(x) > 0;
    }

    int query(int x, int y, int bm) {
        //if (depth < 5) cout << "Querying node " << depth << " " << bit << " :: " << x << " " << y << " " << bm << " contains? " << contains(x,y) << " sz " << SZ(v) << endl;
        if (depth == 0) return bit;
        int b = bm&(1<<(depth-1));
        if ((b && l->contains(x,y)) || (!r->contains(x,y))) return (bit<<depth) | l->query(x,y,bm);
        return (bit<<depth) | r->query(x,y,bm);
    }
} btree(31,0);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    N = 1;
    cin >> Q;
    FOR(i,1,Q){
        string S; int X, Y; cin >> S >> X >> Y;
        if (S == "Add") {
            al[X].emplace_back(++N,Y);
            query[i] = { 0,N,-1 };
        } else {
            query[i] = { 1,X,Y };
        }
    }

    dt = 0, dist[1] = 0, dfs(1);
    //FOR(i,1,N){
    //    cout << i << " :: " << pre[i] << " " << pst[i] << " :: " << dist[i] << endl;
    //}

    btree.update(0, 1);
    FOR(i,1,Q){
        Query q = query[i];
        //cout << "query " << i << endl;
        if (q.t == 0) {
            btree.update(dist[q.x], pre[q.x]);
        } else {
            cout << (dist[q.x] ^ btree.query(pre[q.y], pst[q.y], dist[q.x])) << '\n';
        }
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5504 KB Output is correct
2 Correct 8 ms 5632 KB Output is correct
3 Correct 8 ms 5888 KB Output is correct
4 Correct 8 ms 6016 KB Output is correct
5 Correct 8 ms 5376 KB Output is correct
6 Correct 8 ms 5632 KB Output is correct
7 Correct 9 ms 5760 KB Output is correct
8 Correct 9 ms 6144 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 8 ms 5888 KB Output is correct
12 Correct 9 ms 6144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5504 KB Output is correct
2 Correct 8 ms 5632 KB Output is correct
3 Correct 8 ms 5888 KB Output is correct
4 Correct 8 ms 6016 KB Output is correct
5 Correct 8 ms 5376 KB Output is correct
6 Correct 8 ms 5632 KB Output is correct
7 Correct 9 ms 5760 KB Output is correct
8 Correct 9 ms 6144 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 8 ms 5888 KB Output is correct
12 Correct 9 ms 6144 KB Output is correct
13 Correct 13 ms 7808 KB Output is correct
14 Correct 17 ms 10112 KB Output is correct
15 Correct 19 ms 12416 KB Output is correct
16 Correct 22 ms 14592 KB Output is correct
17 Correct 15 ms 7552 KB Output is correct
18 Correct 17 ms 9984 KB Output is correct
19 Correct 19 ms 12288 KB Output is correct
20 Correct 22 ms 14336 KB Output is correct
21 Correct 14 ms 7680 KB Output is correct
22 Correct 17 ms 9984 KB Output is correct
23 Correct 19 ms 12288 KB Output is correct
24 Correct 22 ms 14336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1626 ms 202320 KB Output is correct
2 Correct 2478 ms 378812 KB Output is correct
3 Runtime error 2955 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5504 KB Output is correct
2 Correct 8 ms 5632 KB Output is correct
3 Correct 8 ms 5888 KB Output is correct
4 Correct 8 ms 6016 KB Output is correct
5 Correct 8 ms 5376 KB Output is correct
6 Correct 8 ms 5632 KB Output is correct
7 Correct 9 ms 5760 KB Output is correct
8 Correct 9 ms 6144 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 8 ms 5888 KB Output is correct
12 Correct 9 ms 6144 KB Output is correct
13 Correct 13 ms 7808 KB Output is correct
14 Correct 17 ms 10112 KB Output is correct
15 Correct 19 ms 12416 KB Output is correct
16 Correct 22 ms 14592 KB Output is correct
17 Correct 15 ms 7552 KB Output is correct
18 Correct 17 ms 9984 KB Output is correct
19 Correct 19 ms 12288 KB Output is correct
20 Correct 22 ms 14336 KB Output is correct
21 Correct 14 ms 7680 KB Output is correct
22 Correct 17 ms 9984 KB Output is correct
23 Correct 19 ms 12288 KB Output is correct
24 Correct 22 ms 14336 KB Output is correct
25 Correct 1626 ms 202320 KB Output is correct
26 Correct 2478 ms 378812 KB Output is correct
27 Runtime error 2955 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Halted 0 ms 0 KB -