Submission #643266

# Submission time Handle Problem Language Result Execution time Memory
643266 2022-09-21T15:32:51 Z Phucdang2k5 Klasika (COCI20_klasika) C++17
110 / 110
2830 ms 475332 KB
//  ---PhucDang---  //
#include<bits/stdc++.h>
#define name "practice"
#define maxn 200010
#define oo LLONG_MAX
#define INF INT_MAX
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define CONST
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define e endl
using namespace std;
typedef long long ll;
template<class T> void MIN(T &A, T B) {A=min(A,B);}
template<class T> void MAX(T &A, T B) {A=max(A,B);}
template<class T> void SUM(T &A, T B) {A=A+B;}
template<class T> void HIEU(T &A, T B) {A=A-B;}
int dis[maxn],q;
vector<int>vec[maxn];

struct Data{
    bool type;
    int u,v;
};
vector<Data>Q;
int tail[maxn],num[maxn],timedfs=0;

void preDFS(int u, int par){
    num[u]=++timedfs;
    for(int v: vec[u]){
        if(v==par) continue;
        preDFS(v,u);
    }
    tail[u]=timedfs;
}

void pre(void){
    int curr=1;
    fo(i,1,q){
        string type;
        int a,b;
        cin>>type>>a>>b;
        if(type=="Add"){
            ++curr;
            vec[a].pb(curr);
            vec[curr].pb(a);
            dis[curr]=dis[a]^b;
            Q.pb({false,a,curr});
        }
        else Q.pb({true,a,b});
    }
    preDFS(1,0);
}

struct node{
    int a[2];
    set<int>id;
    node(){
        a[0]=a[1]=0;
        id.clear();
    }
};
vector<node>trie;

void add(int pos, int depth, int val, int num){
    trie[pos].id.insert(num);
    if(depth==0) return;
    bool bit=(val>>(depth-1))&1;
    int u=trie[pos].a[bit];
    if(u==0){
        trie.pb(node());
        trie[pos].a[bit]=trie.size()-1;
        u=trie.size()-1;
    }
    add(u,depth-1,val,num);
}

bool check(set<int> &s, int l, int r){
    if(s.lower_bound(l)==s.upper_bound(r)) return false;
    return true;
}

int get(int pos, int depth, int l, int r, int xorval){
    if(depth==0) return 0;
    int u1=trie[pos].a[1];
    int u0=trie[pos].a[0];
    if((xorval>>(depth-1))&1) swap(u1,u0);
    if(u1&&check(trie[u1].id,l,r)){
        return (1<<(depth-1))+get(u1,depth-1,l,r,xorval);
    }
    else{
        return get(u0,depth-1,l,r,xorval);
    }
}

void process(void){
    pre();
    trie.pb(node());
    add(0,30,dis[1],num[1]);
    for(auto [type,u,v]: Q){
        if(type==false) add(0,30,dis[v],num[v]);
        else cout<<get(0,30,num[v],tail[v],dis[u])<<e;

    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//    freopen(name".inp","r",stdin);
//    freopen(name".out","w",stdout);
    cin>>q;
    process();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5204 KB Output is correct
2 Correct 4 ms 5152 KB Output is correct
3 Correct 4 ms 5460 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 3 ms 5088 KB Output is correct
6 Correct 4 ms 5156 KB Output is correct
7 Correct 3 ms 5408 KB Output is correct
8 Correct 4 ms 5412 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 3 ms 5408 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
12 Correct 3 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5204 KB Output is correct
2 Correct 4 ms 5152 KB Output is correct
3 Correct 4 ms 5460 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 3 ms 5088 KB Output is correct
6 Correct 4 ms 5156 KB Output is correct
7 Correct 3 ms 5408 KB Output is correct
8 Correct 4 ms 5412 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 3 ms 5408 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
12 Correct 3 ms 5460 KB Output is correct
13 Correct 8 ms 6476 KB Output is correct
14 Correct 10 ms 8072 KB Output is correct
15 Correct 12 ms 8372 KB Output is correct
16 Correct 13 ms 11188 KB Output is correct
17 Correct 9 ms 6512 KB Output is correct
18 Correct 11 ms 7996 KB Output is correct
19 Correct 11 ms 8324 KB Output is correct
20 Correct 11 ms 9220 KB Output is correct
21 Correct 9 ms 6476 KB Output is correct
22 Correct 10 ms 8036 KB Output is correct
23 Correct 10 ms 8328 KB Output is correct
24 Correct 11 ms 9216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1185 ms 120104 KB Output is correct
2 Correct 1682 ms 235420 KB Output is correct
3 Correct 1995 ms 289596 KB Output is correct
4 Correct 2459 ms 475196 KB Output is correct
5 Correct 1063 ms 118284 KB Output is correct
6 Correct 1670 ms 231720 KB Output is correct
7 Correct 2112 ms 284820 KB Output is correct
8 Correct 2586 ms 467736 KB Output is correct
9 Correct 1025 ms 118456 KB Output is correct
10 Correct 1504 ms 232316 KB Output is correct
11 Correct 2073 ms 286676 KB Output is correct
12 Correct 2512 ms 469032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5204 KB Output is correct
2 Correct 4 ms 5152 KB Output is correct
3 Correct 4 ms 5460 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 3 ms 5088 KB Output is correct
6 Correct 4 ms 5156 KB Output is correct
7 Correct 3 ms 5408 KB Output is correct
8 Correct 4 ms 5412 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 3 ms 5408 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
12 Correct 3 ms 5460 KB Output is correct
13 Correct 8 ms 6476 KB Output is correct
14 Correct 10 ms 8072 KB Output is correct
15 Correct 12 ms 8372 KB Output is correct
16 Correct 13 ms 11188 KB Output is correct
17 Correct 9 ms 6512 KB Output is correct
18 Correct 11 ms 7996 KB Output is correct
19 Correct 11 ms 8324 KB Output is correct
20 Correct 11 ms 9220 KB Output is correct
21 Correct 9 ms 6476 KB Output is correct
22 Correct 10 ms 8036 KB Output is correct
23 Correct 10 ms 8328 KB Output is correct
24 Correct 11 ms 9216 KB Output is correct
25 Correct 1185 ms 120104 KB Output is correct
26 Correct 1682 ms 235420 KB Output is correct
27 Correct 1995 ms 289596 KB Output is correct
28 Correct 2459 ms 475196 KB Output is correct
29 Correct 1063 ms 118284 KB Output is correct
30 Correct 1670 ms 231720 KB Output is correct
31 Correct 2112 ms 284820 KB Output is correct
32 Correct 2586 ms 467736 KB Output is correct
33 Correct 1025 ms 118456 KB Output is correct
34 Correct 1504 ms 232316 KB Output is correct
35 Correct 2073 ms 286676 KB Output is correct
36 Correct 2512 ms 469032 KB Output is correct
37 Correct 1531 ms 120608 KB Output is correct
38 Correct 2082 ms 235752 KB Output is correct
39 Correct 2369 ms 291956 KB Output is correct
40 Correct 2665 ms 475332 KB Output is correct
41 Correct 1600 ms 118576 KB Output is correct
42 Correct 2213 ms 232120 KB Output is correct
43 Correct 2551 ms 285060 KB Output is correct
44 Correct 2830 ms 468072 KB Output is correct
45 Correct 1752 ms 118908 KB Output is correct
46 Correct 2331 ms 232700 KB Output is correct
47 Correct 2522 ms 285656 KB Output is correct
48 Correct 2723 ms 469428 KB Output is correct