Submission #844890

# Submission time Handle Problem Language Result Execution time Memory
844890 2023-09-06T07:13:51 Z vjudge1 Klasika (COCI20_klasika) C++14
110 / 110
2828 ms 442796 KB
// Aber der schlimmste Fiend, dem du begegnen kannst, wirst du immer dir selber sein
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define rev reverse
#define all(x) x.begin(),x.end()
#define acc accumulate
#define sz size()
#define MOD 1000000007
#define rall(x) x.rbegin(),x.rend()
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const int N = 2e5 + 5;
struct node{
    node *one = NULL, *zero = NULL;
    set<int> index_set;
};
struct trie{
    node root;
    void insert(node *cur, int len, int x, int in){
        cur->index_set.insert(in);
        if(len == -1){
            return;
        }
        int bit = (x >> len) & 1;
        if(bit){
            if(cur->one == NULL){
                cur->one = new node;
            }
            insert(cur->one, len-1, x, in);
        }
        else{
            if(cur->zero == NULL){
                cur->zero = new node;
            }
            insert(cur->zero, len-1, x, in);
        }
    }
    int find(node *cur, int len, int x, int l, int r){
        if(len == -1){
            return 0;
        }
        int bit = (x >> len) & 1;
        if(bit){
            if(cur->zero != NULL && cur->zero->index_set.lower_bound(l) != cur->zero->index_set.upper_bound(r)){
                return find(cur->zero, len-1, x, l, r) + (1 << len);
            }
            else{
                return find(cur->one, len-1, x, l, r);
            }
        }
        if(cur->one != NULL && cur->one->index_set.lower_bound(l) != cur->one->index_set.upper_bound(r)){
           return find(cur->one, len-1, x, l, r) + (1 << len);
        }
        return find(cur->zero, len-1, x, l, r);
    }
};
vector<int> adj[N];
int gir[N], cik[N], ti = 0, xor_value[N];
void dfs(int node, int dad){
    gir[node] = ++ti;
    for(int i = 0; i < adj[node].sz; i++){
        if(adj[node][i] != dad){
            dfs(adj[node][i], node);
        }
    }
    cik[node] = ti;
}
trie tree;
inline void solve(){
    int n;
    cin >> n;
    pair<string, pair<int, int> > a[n];
    int node_count = 1;
    for(int i = 0; i < n; i++){
        cin >> a[i].ff >> a[i].ss.ff >> a[i].ss.ss;
        if(a[i].ff == "Add"){
            node_count++;
            adj[a[i].ss.ff].emplace_back(node_count);
            adj[node_count].emplace_back(a[i].ss.ff);
            xor_value[node_count] = xor_value[a[i].ss.ff] ^ a[i].ss.ss;
        }
    }
    dfs(1, 1);
    node_count = 1;
    tree.insert(&tree.root, 30, 0, 1);
    for(int i = 0; i < n; i++){
        if(a[i].ff == "Add"){
            node_count++;
            tree.insert(&tree.root, 30, xor_value[node_count], gir[node_count]);
        }
        else{
            cout << tree.find(&tree.root, 30, xor_value[a[i].ss.ff], gir[a[i].ss.ss], cik[a[i].ss.ss]) << endl;
        }
    }
}
int main(){
    fast_io
    int t;
    t = 1;
    while(t--) solve();
}

Compilation message

klasika.cpp: In function 'void dfs(int, int)':
klasika.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0; i < adj[node].sz; i++){
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5464 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5464 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5464 KB Output is correct
10 Correct 2 ms 5464 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5464 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5464 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5464 KB Output is correct
10 Correct 2 ms 5464 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5720 KB Output is correct
13 Correct 6 ms 6744 KB Output is correct
14 Correct 7 ms 8024 KB Output is correct
15 Correct 7 ms 9308 KB Output is correct
16 Correct 8 ms 10332 KB Output is correct
17 Correct 6 ms 6488 KB Output is correct
18 Correct 7 ms 7768 KB Output is correct
19 Correct 8 ms 9048 KB Output is correct
20 Correct 10 ms 10328 KB Output is correct
21 Correct 9 ms 6744 KB Output is correct
22 Correct 7 ms 7768 KB Output is correct
23 Correct 9 ms 9048 KB Output is correct
24 Correct 8 ms 10328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1130 ms 126760 KB Output is correct
2 Correct 1301 ms 234584 KB Output is correct
3 Correct 1692 ms 336496 KB Output is correct
4 Correct 1998 ms 438860 KB Output is correct
5 Correct 847 ms 125944 KB Output is correct
6 Correct 1290 ms 232804 KB Output is correct
7 Correct 1677 ms 333844 KB Output is correct
8 Correct 2066 ms 434484 KB Output is correct
9 Correct 792 ms 125232 KB Output is correct
10 Correct 1154 ms 233104 KB Output is correct
11 Correct 1464 ms 335360 KB Output is correct
12 Correct 1771 ms 435528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5464 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5464 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5464 KB Output is correct
10 Correct 2 ms 5464 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5720 KB Output is correct
13 Correct 6 ms 6744 KB Output is correct
14 Correct 7 ms 8024 KB Output is correct
15 Correct 7 ms 9308 KB Output is correct
16 Correct 8 ms 10332 KB Output is correct
17 Correct 6 ms 6488 KB Output is correct
18 Correct 7 ms 7768 KB Output is correct
19 Correct 8 ms 9048 KB Output is correct
20 Correct 10 ms 10328 KB Output is correct
21 Correct 9 ms 6744 KB Output is correct
22 Correct 7 ms 7768 KB Output is correct
23 Correct 9 ms 9048 KB Output is correct
24 Correct 8 ms 10328 KB Output is correct
25 Correct 1130 ms 126760 KB Output is correct
26 Correct 1301 ms 234584 KB Output is correct
27 Correct 1692 ms 336496 KB Output is correct
28 Correct 1998 ms 438860 KB Output is correct
29 Correct 847 ms 125944 KB Output is correct
30 Correct 1290 ms 232804 KB Output is correct
31 Correct 1677 ms 333844 KB Output is correct
32 Correct 2066 ms 434484 KB Output is correct
33 Correct 792 ms 125232 KB Output is correct
34 Correct 1154 ms 233104 KB Output is correct
35 Correct 1464 ms 335360 KB Output is correct
36 Correct 1771 ms 435528 KB Output is correct
37 Correct 1338 ms 127636 KB Output is correct
38 Correct 1724 ms 237904 KB Output is correct
39 Correct 1964 ms 342412 KB Output is correct
40 Correct 2076 ms 442796 KB Output is correct
41 Correct 1349 ms 129080 KB Output is correct
42 Correct 1789 ms 235972 KB Output is correct
43 Correct 2037 ms 337380 KB Output is correct
44 Correct 2295 ms 437244 KB Output is correct
45 Correct 1431 ms 128708 KB Output is correct
46 Correct 1946 ms 236260 KB Output is correct
47 Correct 2152 ms 337284 KB Output is correct
48 Correct 2828 ms 439136 KB Output is correct