Submission #308338

# Submission time Handle Problem Language Result Execution time Memory
308338 2020-10-01T00:04:39 Z ErdosSzekeres Klasika (COCI20_klasika) C++14
110 / 110
4054 ms 499960 KB
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<int,int>
const int MAXN = 3e5+7;
int q;
int tp[MAXN], a[MAXN], b[MAXN], d[MAXN], t=0, ent[MAXN], sai[MAXN];
int fe[8*MAXN], fd[8*MAXN], node_counter = 0;
set<int> aux[8*MAXN];//entry times
int create(){
    node_counter++;
    fe[node_counter] = -1;
    fd[node_counter] = -1;
    aux[node_counter].insert((1<<30)+1);
    return node_counter;
}
vector<pii> G[MAXN];
void inserir(int idx, int depth, int val, int et){
    aux[idx].insert(et);
    if(depth < 0)return;
    if((val&(1<<depth))){//go right
        if(fd[idx] == -1)fd[idx] = create();
        inserir(fd[idx], depth-1, val, et);
    }else{
        if(fe[idx] == -1)fe[idx] = create();
        inserir(fe[idx], depth-1, val, et);
    }
}
void dfs(int u){
    t++; ent[u] = t;
    for(pii viz : G[u]){
        d[viz.first] = (d[u]^viz.second);
        dfs(viz.first);
    }
    sai[u] = t;
}
int query(int idx, int depth, int val, int node){
    if(depth < 0)return 0;
    if((val&(1<<depth))){//i want to go left
        if(fe[idx] == -1){//but i cant
            return query(fd[idx], depth-1, val, node);
        }else{
            int tst = *aux[fe[idx]].lower_bound(ent[node]);
            if(tst>=ent[node] && tst <= sai[node]){//go!!
                //cout<<tst<<" "<<ent[node]<<" "<<sai[node]<<"  --> "<<node<<endl;
                return (1<<depth) + query(fe[idx], depth-1, val, node);
            }
            return query(fd[idx], depth-1, val, node);
        }
    }else{//i want to go right
        if(fd[idx] == -1){//but i cant
            return query(fe[idx], depth-1, val, node);
        }else{
            int tst = *aux[fd[idx]].lower_bound(ent[node]);
            if(tst>=ent[node] && tst <= sai[node]){//go!!
                //cout<<tst<<" "<<ent[node]<<" "<<sai[node]<<"  --> "<<node<<endl;
                return (1<<depth) + query(fd[idx], depth-1, val, node);
            }
            return query(fe[idx], depth-1, val, node);
        }
    }
}
int main(){
    fastio; cin>>q;
    for(int i=0; i<q; i++){
        string ii; cin>>ii>>a[i]>>b[i];
        tp[i] = (ii=="Add") ? 0 : 1;
    }
    int raiz = create();
    int id = 1;
    for(int i=0; i<q; i++){//build tree and compute euler tour
        if(tp[i] == 1)continue;
        id++;
        G[a[i]].push_back({id, b[i]});
    }
    dfs(1);
    inserir(1, 30, 0, ent[1]);
    id = 1;
    for(int i=0; i<q; i++){
        if(tp[i] == 0){
            id++;
            inserir(1, 30, d[id], ent[id]);
        }else{
            cout << query(raiz, 30, d[a[i]], b[i]) << endl;//max xor with d[a[i]] in subtree of b[i]
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 81 ms 120312 KB Output is correct
2 Correct 84 ms 120440 KB Output is correct
3 Correct 83 ms 120568 KB Output is correct
4 Correct 86 ms 120696 KB Output is correct
5 Correct 81 ms 120312 KB Output is correct
6 Correct 82 ms 120424 KB Output is correct
7 Correct 81 ms 120440 KB Output is correct
8 Correct 82 ms 120568 KB Output is correct
9 Correct 82 ms 120312 KB Output is correct
10 Correct 80 ms 120440 KB Output is correct
11 Correct 80 ms 120568 KB Output is correct
12 Correct 81 ms 120568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 120312 KB Output is correct
2 Correct 84 ms 120440 KB Output is correct
3 Correct 83 ms 120568 KB Output is correct
4 Correct 86 ms 120696 KB Output is correct
5 Correct 81 ms 120312 KB Output is correct
6 Correct 82 ms 120424 KB Output is correct
7 Correct 81 ms 120440 KB Output is correct
8 Correct 82 ms 120568 KB Output is correct
9 Correct 82 ms 120312 KB Output is correct
10 Correct 80 ms 120440 KB Output is correct
11 Correct 80 ms 120568 KB Output is correct
12 Correct 81 ms 120568 KB Output is correct
13 Correct 90 ms 121336 KB Output is correct
14 Correct 90 ms 122556 KB Output is correct
15 Correct 99 ms 123708 KB Output is correct
16 Correct 94 ms 124536 KB Output is correct
17 Correct 90 ms 121336 KB Output is correct
18 Correct 91 ms 122360 KB Output is correct
19 Correct 93 ms 123468 KB Output is correct
20 Correct 95 ms 124408 KB Output is correct
21 Correct 88 ms 121336 KB Output is correct
22 Correct 94 ms 122360 KB Output is correct
23 Correct 92 ms 123384 KB Output is correct
24 Correct 92 ms 124408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1554 ms 221736 KB Output is correct
2 Correct 2240 ms 315108 KB Output is correct
3 Correct 2895 ms 405208 KB Output is correct
4 Correct 3668 ms 495840 KB Output is correct
5 Correct 1554 ms 220280 KB Output is correct
6 Correct 2294 ms 312184 KB Output is correct
7 Correct 3001 ms 400560 KB Output is correct
8 Correct 3729 ms 489720 KB Output is correct
9 Correct 1577 ms 219760 KB Output is correct
10 Correct 2278 ms 312824 KB Output is correct
11 Correct 3028 ms 402808 KB Output is correct
12 Correct 3713 ms 491380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 120312 KB Output is correct
2 Correct 84 ms 120440 KB Output is correct
3 Correct 83 ms 120568 KB Output is correct
4 Correct 86 ms 120696 KB Output is correct
5 Correct 81 ms 120312 KB Output is correct
6 Correct 82 ms 120424 KB Output is correct
7 Correct 81 ms 120440 KB Output is correct
8 Correct 82 ms 120568 KB Output is correct
9 Correct 82 ms 120312 KB Output is correct
10 Correct 80 ms 120440 KB Output is correct
11 Correct 80 ms 120568 KB Output is correct
12 Correct 81 ms 120568 KB Output is correct
13 Correct 90 ms 121336 KB Output is correct
14 Correct 90 ms 122556 KB Output is correct
15 Correct 99 ms 123708 KB Output is correct
16 Correct 94 ms 124536 KB Output is correct
17 Correct 90 ms 121336 KB Output is correct
18 Correct 91 ms 122360 KB Output is correct
19 Correct 93 ms 123468 KB Output is correct
20 Correct 95 ms 124408 KB Output is correct
21 Correct 88 ms 121336 KB Output is correct
22 Correct 94 ms 122360 KB Output is correct
23 Correct 92 ms 123384 KB Output is correct
24 Correct 92 ms 124408 KB Output is correct
25 Correct 1554 ms 221736 KB Output is correct
26 Correct 2240 ms 315108 KB Output is correct
27 Correct 2895 ms 405208 KB Output is correct
28 Correct 3668 ms 495840 KB Output is correct
29 Correct 1554 ms 220280 KB Output is correct
30 Correct 2294 ms 312184 KB Output is correct
31 Correct 3001 ms 400560 KB Output is correct
32 Correct 3729 ms 489720 KB Output is correct
33 Correct 1577 ms 219760 KB Output is correct
34 Correct 2278 ms 312824 KB Output is correct
35 Correct 3028 ms 402808 KB Output is correct
36 Correct 3713 ms 491380 KB Output is correct
37 Correct 2314 ms 225704 KB Output is correct
38 Correct 2917 ms 318200 KB Output is correct
39 Correct 3402 ms 410872 KB Output is correct
40 Correct 3779 ms 499960 KB Output is correct
41 Correct 2400 ms 223560 KB Output is correct
42 Correct 2989 ms 315328 KB Output is correct
43 Correct 3516 ms 404224 KB Output is correct
44 Correct 4030 ms 492664 KB Output is correct
45 Correct 2507 ms 223168 KB Output is correct
46 Correct 3218 ms 316092 KB Output is correct
47 Correct 3716 ms 404876 KB Output is correct
48 Correct 4054 ms 494876 KB Output is correct