Submission #1090921

# Submission time Handle Problem Language Result Execution time Memory
1090921 2024-09-19T07:22:17 Z fryingduc Klasika (COCI20_klasika) C++17
110 / 110
2292 ms 476716 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif

const int maxn = 2e5 + 5;
const int lg = 30;
int q;
int n;
int tin[maxn], tout[maxn], timer;
int op[maxn], qx[maxn], qy[maxn];
int par[maxn];
vector<pair<int, int>> g[maxn];
int dep[maxn], h[maxn];

void pre_dfs(int u) {
  tin[u] = ++timer;
  for(auto e:g[u]) {
    int v = e.first, w = e.second;
    dep[v] = dep[u] ^ w;
    h[v] = h[u] + 1;
    pre_dfs(v);
  }
  tout[u] = timer;
}
struct trie {
    struct node {
        set<int> all;
        int nt[2];
        node(){
            nt[0] = nt[1] = 0;
        }
    };
    vector<node> t;
    int cc;
    trie() {
        t.push_back({});
        t.push_back({});
        cc = 1;
    }
    vector<int> :: iterator it;
    void add(int p, int x){
        int v = 1;
        for (int i = lg; i >= 0; i--){
            bool bit = (x >> i) & 1;
            if (!t[v].nt[bit]){
                t[v].nt[bit] = ++cc;
                t.push_back({});
            }
            v = t[v].nt[bit];
            t[v].all.insert(p);
        }
    }
    int get(int l, int r, int x){
        int out = 0, v = 1;
        for (int i = lg; i >= 0; i--){
            bool bit = (x >> i) & 1;
            int k = t[v].nt[!bit];
            auto it = t[k].all.lower_bound(l);
            if (it != t[k].all.end() && (*it) <= r){
                v = k;
                out += (1 << i);
                continue;
            }
            v = t[v].nt[bit];
        }
        return out;
    }
} t;
 
void solve() {
  cin >> q;
  string s;
  n = 1;
  for(int i = 1; i <= q; ++i) {
    cin >> s >> qx[i] >> qy[i]; 
    if(s[0] == 'Q') {
      op[i] = 1;
    }
    
    if(!op[i]) {
      ++n;
      par[n] = qx[i];
      g[qx[i]].push_back({n, qy[i]});
      qx[i] = n;
    }
  }
  pre_dfs(1);
  t.add(1, 0);
  
  for(int i = 1; i <= q; ++i) {
    if(!op[i]) {
      t.add(tin[qx[i]], dep[qx[i]]);
    }
    else {
      int u = qx[i], v = qy[i];
      cout << t.get(tin[v], tout[v], dep[u]) << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  solve();

  return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5468 KB Output is correct
4 Correct 3 ms 5424 KB Output is correct
5 Correct 4 ms 5164 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 4 ms 5468 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 3 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5468 KB Output is correct
4 Correct 3 ms 5424 KB Output is correct
5 Correct 4 ms 5164 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 4 ms 5468 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 3 ms 5468 KB Output is correct
13 Correct 5 ms 6536 KB Output is correct
14 Correct 7 ms 8188 KB Output is correct
15 Correct 8 ms 8496 KB Output is correct
16 Correct 10 ms 11248 KB Output is correct
17 Correct 5 ms 6520 KB Output is correct
18 Correct 7 ms 8152 KB Output is correct
19 Correct 8 ms 8244 KB Output is correct
20 Correct 13 ms 9244 KB Output is correct
21 Correct 5 ms 6516 KB Output is correct
22 Correct 7 ms 8032 KB Output is correct
23 Correct 8 ms 8240 KB Output is correct
24 Correct 10 ms 9268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 542 ms 117496 KB Output is correct
2 Correct 955 ms 235944 KB Output is correct
3 Correct 1383 ms 290632 KB Output is correct
4 Correct 1769 ms 476436 KB Output is correct
5 Correct 549 ms 117992 KB Output is correct
6 Correct 1046 ms 231256 KB Output is correct
7 Correct 1599 ms 284184 KB Output is correct
8 Correct 2099 ms 466808 KB Output is correct
9 Correct 536 ms 118292 KB Output is correct
10 Correct 983 ms 232096 KB Output is correct
11 Correct 1436 ms 286652 KB Output is correct
12 Correct 1925 ms 468524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5468 KB Output is correct
4 Correct 3 ms 5424 KB Output is correct
5 Correct 4 ms 5164 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 4 ms 5468 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 3 ms 5468 KB Output is correct
13 Correct 5 ms 6536 KB Output is correct
14 Correct 7 ms 8188 KB Output is correct
15 Correct 8 ms 8496 KB Output is correct
16 Correct 10 ms 11248 KB Output is correct
17 Correct 5 ms 6520 KB Output is correct
18 Correct 7 ms 8152 KB Output is correct
19 Correct 8 ms 8244 KB Output is correct
20 Correct 13 ms 9244 KB Output is correct
21 Correct 5 ms 6516 KB Output is correct
22 Correct 7 ms 8032 KB Output is correct
23 Correct 8 ms 8240 KB Output is correct
24 Correct 10 ms 9268 KB Output is correct
25 Correct 542 ms 117496 KB Output is correct
26 Correct 955 ms 235944 KB Output is correct
27 Correct 1383 ms 290632 KB Output is correct
28 Correct 1769 ms 476436 KB Output is correct
29 Correct 549 ms 117992 KB Output is correct
30 Correct 1046 ms 231256 KB Output is correct
31 Correct 1599 ms 284184 KB Output is correct
32 Correct 2099 ms 466808 KB Output is correct
33 Correct 536 ms 118292 KB Output is correct
34 Correct 983 ms 232096 KB Output is correct
35 Correct 1436 ms 286652 KB Output is correct
36 Correct 1925 ms 468524 KB Output is correct
37 Correct 816 ms 121056 KB Output is correct
38 Correct 1158 ms 236452 KB Output is correct
39 Correct 1497 ms 293092 KB Output is correct
40 Correct 1779 ms 476716 KB Output is correct
41 Correct 936 ms 118356 KB Output is correct
42 Correct 1591 ms 231544 KB Output is correct
43 Correct 1962 ms 284468 KB Output is correct
44 Correct 2292 ms 467204 KB Output is correct
45 Correct 973 ms 118792 KB Output is correct
46 Correct 1527 ms 232484 KB Output is correct
47 Correct 1848 ms 285368 KB Output is correct
48 Correct 2203 ms 468780 KB Output is correct