Submission #965547

# Submission time Handle Problem Language Result Execution time Memory
965547 2024-04-18T20:24:56 Z noyancanturk Klasika (COCI20_klasika) C++17
33 / 110
928 ms 520340 KB
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int lim=2e5+500;
const int mod=1e9+7;
const int llim=3e7; 

using pii=pair<int,int>;

struct trie{

    struct node{
        signed c[2]{0,0};
    };

    static node nds[llim];
    static int nextnode;

    using pnode=node*;
    pnode root;

    trie(){root=nds+(nextnode++);}

    void insert(int x){
        pnode cur=root;
        for(int i=29;0<=i;i--){
            if(!cur->c[(x>>i)&1]){
                cur->c[(x>>i)&1]=nextnode++;
            }
            cur=nds+cur->c[(x>>i)&1];
        }
    }

    int search(int x){
        pnode cur=root;
        int ans=0;
        for(int i=29;0<=i;i--){
            if(cur->c[!((x>>i)&1)]){
                if(!((x>>i)&1))ans+=1<<i;
                cur=nds+cur->c[!((x>>i)&1)];
            }else if(cur->c[(x>>i)&1]){
                if((x>>i)&1)ans+=1<<i;
                cur=nds+cur->c[(x>>i)&1];
            }else{
                return 0;
            }
        }
        return ans^x;
    }

};

int trie::nextnode=1;
trie::node trie::nds[llim];

struct segtree{
    trie tree[2*lim];
    int n;
    void update(int p,int val){
        for(p+=n;p;p>>=1)tree[p].insert(val);
    }
    int query(int l,int r,int x){
        int ans=0;
        for(l+=n,r+=n+1;l<r;l>>=1,r>>=1){
            if(l&1){
                ans=max(ans,tree[l++].search(x));
            }
            if(r&1){
                ans=max(ans,tree[--r].search(x));
            }
        }
        return ans;
    }
}st;

struct qdata{
    int ty,x,y;
};

vector<pii>v[lim];
int dist[lim];
int tin[lim],tout[lim],tt=0;

void dfs(int node){
    tin[node]=tt++;
    for(auto[j,c]:v[node]){
        dist[j]=dist[node]^c;
        dfs(j);
    }
    tout[node]=tt-1;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin); freopen(".out","w",stdout);
    cerr<<sizeof(trie::nds)/1000000<<"\n";
#endif
    int n;
    cin>>n;
    qdata q[n];
    int curnode=2;
    for(int i=0;i<n;i++){
        string ty;
        cin>>ty>>q[i].x>>q[i].y;
        if(ty=="Add"){
            q[i].ty=0;
            v[q[i].x].pb({curnode,q[i].y});
            curnode++;
        }else{
            q[i].ty=1;
        }
    }
    dfs(1);
    st.n=tt+50;
    st.update(tin[1],0);
    curnode=2;
    for(int i=0;i<n;i++){
        if(!q[i].ty){
            st.update(tin[curnode],dist[curnode]);
            curnode++;
        }else{
            cout<<st.query(tin[q[i].y],tout[q[i].y],dist[q[i].x])<<"\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 13144 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 13144 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 6 ms 13660 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 15708 KB Output is correct
16 Correct 6 ms 16732 KB Output is correct
17 Correct 6 ms 13656 KB Output is correct
18 Correct 5 ms 14428 KB Output is correct
19 Correct 7 ms 15452 KB Output is correct
20 Correct 6 ms 16472 KB Output is correct
21 Correct 5 ms 13656 KB Output is correct
22 Correct 5 ms 14424 KB Output is correct
23 Correct 6 ms 15452 KB Output is correct
24 Correct 6 ms 16476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 463 ms 141508 KB Output is correct
2 Runtime error 928 ms 520340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 13144 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 6 ms 13660 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 15708 KB Output is correct
16 Correct 6 ms 16732 KB Output is correct
17 Correct 6 ms 13656 KB Output is correct
18 Correct 5 ms 14428 KB Output is correct
19 Correct 7 ms 15452 KB Output is correct
20 Correct 6 ms 16472 KB Output is correct
21 Correct 5 ms 13656 KB Output is correct
22 Correct 5 ms 14424 KB Output is correct
23 Correct 6 ms 15452 KB Output is correct
24 Correct 6 ms 16476 KB Output is correct
25 Correct 463 ms 141508 KB Output is correct
26 Runtime error 928 ms 520340 KB Execution killed with signal 11
27 Halted 0 ms 0 KB -