Submission #889425

# Submission time Handle Problem Language Result Execution time Memory
889425 2023-12-19T16:15:28 Z Alish Klasika (COCI20_klasika) C++17
110 / 110
2057 ms 424024 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long int	ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;


#define F		        first
#define S		        second
#define pb		        push_back
#define endl            '\n'
#define Mp		        make_pair
#define all(x)          x.begin(), x.end()
#define debug(x)        cerr << #x << " = " << x << endl;
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);


ll mod = 1e9+7 ;

const int N = 2e5+23, L=31;


int h[N];
struct node {
	node* ch[2];
	set<int> ss;

	node() {
		ch[0] = ch[1] = nullptr;
	}
}root;

int st[N], ft[N], tim=0;
vector<int> g[N];
vector<pair<int, pii> > Q;
int cnt=1;
int tr;

void dfs(int v){
    st[v]=tim++;
    for (int u: g[v]) dfs(u);
    ft[v]=tim;
}

void add(int x, int pp){
    node* cur=&root;

    for (int i=L-1; i>=0; i--){
        int t=(x>>i&1);
        if(cur->ch[t]==nullptr) cur->ch[t]= new node();

        cur=cur->ch[t];
        cur->ss.insert(pp);
    }
}

int get(int x, int v){
    node* cur=&root;
    int ans=0;
    for (int i=L-1; i>=0; i--){
        int t=(x>>i&1);
        t=1-t;
        if(cur->ch[t]!=nullptr){
            auto x=cur->ch[t]->ss.lower_bound(st[v]);

            if(x==cur->ch[t]->ss.end() || *x>=ft[v]){
                cur=cur->ch[1-t];
            }
            else{
                ans+=(1<<i);
                cur=cur->ch[t];
            }
        }
        else{
            cur=cur->ch[1-t];
        }
    }
    return ans;
}

int main()
{
    fast_io
    int q; cin>>q;
    for (int i=0; i<q; i++){
        string s; cin>>s;
        if(s=="Add"){
             ll u, w;
            cin>>u>>w;
            cnt++;
            h[cnt]=h[u]^w;
            g[u].pb(cnt);
            Q.pb({0, {cnt, u}});
        }
        else{
                int u, v; cin>>v>>u;
            Q.pb({1, {v, u}});
        }
    }
    dfs(1);

    for (int i=0; i<=cnt; i++){
        g[i].clear();
        g[i].shrink_to_fit();
    }
    add(0, st[1]);

    for (auto pp: Q){
        int t=pp.F, v=pp.S.F, u=pp.S.S;
        if(!t){
            add(h[v], st[v]);
        }
        else{
            cout<<get(h[v], u)<<endl;
        }
    }

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7256 KB Output is correct
5 Correct 2 ms 6840 KB Output is correct
6 Correct 1 ms 7004 KB Output is correct
7 Correct 2 ms 7004 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 7052 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7256 KB Output is correct
5 Correct 2 ms 6840 KB Output is correct
6 Correct 1 ms 7004 KB Output is correct
7 Correct 2 ms 7004 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 7052 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 4 ms 8028 KB Output is correct
14 Correct 5 ms 9308 KB Output is correct
15 Correct 6 ms 10588 KB Output is correct
16 Correct 8 ms 11608 KB Output is correct
17 Correct 4 ms 8028 KB Output is correct
18 Correct 5 ms 9128 KB Output is correct
19 Correct 6 ms 10332 KB Output is correct
20 Correct 8 ms 11612 KB Output is correct
21 Correct 4 ms 8028 KB Output is correct
22 Correct 5 ms 9308 KB Output is correct
23 Correct 6 ms 10332 KB Output is correct
24 Correct 7 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 119372 KB Output is correct
2 Correct 766 ms 222692 KB Output is correct
3 Correct 1178 ms 320588 KB Output is correct
4 Correct 1516 ms 419900 KB Output is correct
5 Correct 502 ms 118380 KB Output is correct
6 Correct 877 ms 220560 KB Output is correct
7 Correct 1400 ms 318688 KB Output is correct
8 Correct 1808 ms 416588 KB Output is correct
9 Correct 466 ms 118240 KB Output is correct
10 Correct 835 ms 220924 KB Output is correct
11 Correct 1235 ms 320764 KB Output is correct
12 Correct 1491 ms 417544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7256 KB Output is correct
5 Correct 2 ms 6840 KB Output is correct
6 Correct 1 ms 7004 KB Output is correct
7 Correct 2 ms 7004 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 7052 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 4 ms 8028 KB Output is correct
14 Correct 5 ms 9308 KB Output is correct
15 Correct 6 ms 10588 KB Output is correct
16 Correct 8 ms 11608 KB Output is correct
17 Correct 4 ms 8028 KB Output is correct
18 Correct 5 ms 9128 KB Output is correct
19 Correct 6 ms 10332 KB Output is correct
20 Correct 8 ms 11612 KB Output is correct
21 Correct 4 ms 8028 KB Output is correct
22 Correct 5 ms 9308 KB Output is correct
23 Correct 6 ms 10332 KB Output is correct
24 Correct 7 ms 11612 KB Output is correct
25 Correct 458 ms 119372 KB Output is correct
26 Correct 766 ms 222692 KB Output is correct
27 Correct 1178 ms 320588 KB Output is correct
28 Correct 1516 ms 419900 KB Output is correct
29 Correct 502 ms 118380 KB Output is correct
30 Correct 877 ms 220560 KB Output is correct
31 Correct 1400 ms 318688 KB Output is correct
32 Correct 1808 ms 416588 KB Output is correct
33 Correct 466 ms 118240 KB Output is correct
34 Correct 835 ms 220924 KB Output is correct
35 Correct 1235 ms 320764 KB Output is correct
36 Correct 1491 ms 417544 KB Output is correct
37 Correct 914 ms 123832 KB Output is correct
38 Correct 1287 ms 225272 KB Output is correct
39 Correct 1624 ms 327432 KB Output is correct
40 Correct 1744 ms 424024 KB Output is correct
41 Correct 994 ms 122260 KB Output is correct
42 Correct 1471 ms 223492 KB Output is correct
43 Correct 1781 ms 321924 KB Output is correct
44 Correct 2057 ms 420320 KB Output is correct
45 Correct 959 ms 120972 KB Output is correct
46 Correct 1462 ms 224288 KB Output is correct
47 Correct 1688 ms 322156 KB Output is correct
48 Correct 1847 ms 421196 KB Output is correct