답안 #1090915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090915 2024-09-19T07:11:34 Z fryingduc Klasika (COCI20_klasika) C++17
33 / 110
621 ms 524288 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 = 19;
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 {
  const static int lg = 30;
  struct node {
    node *child[2];
    int cnt;
    node() {
      child[0] = child[1] = nullptr;
      cnt = 0;
    }
  } *root;
  trie() {
    root = new node();
  }
  void add(int x) {
    node *p = root;
    for(int i = lg; i >= 0; --i) {
      int c = (x >> i & 1);
      if(p->child[c] == nullptr) {
        p->child[c] = new node();
      }
      p = p->child[c];
      p->cnt++;
    }
  }
  int get(int x) {
    node *p = root;
    int ans = 0;
    for(int i = lg; i >= 0; --i) {
      int c = (x >> i & 1);
      if(p->child[c ^ 1] and p->child[c ^ 1]->cnt) {
        ans |= (1 << i);
        p = p->child[c ^ 1];
      }
      else {
        if(p->child[c] == nullptr) {
          return ans;
        }
        p = p->child[c];
      }
    }
    return ans;
  }
} tree[maxn * 4];
struct segment_tree {
  int n;
  segment_tree() {}
  segment_tree(int n) : n(n) {}
  void update(int ind, int l, int r, int pos, int val) {
    tree[ind].add(val);
    if(l == r) {
      return;
    }
    int mid = (l + r) >> 1;
    if(pos <= mid) {
      update(ind << 1, l, mid, pos, val);
    }
    else {
      update(ind << 1 | 1, mid + 1, r, pos, val);
    }
  }
  int get(int ind, int l, int r, int x, int y, int val) {
    if(l > y || r < x) return 0;
    if(x <= l and r <= y) {
      return tree[ind].get(val);
    }
    int mid = (l + r) >> 1;
    return max(get(ind << 1, l, mid, x, y, val), get(ind << 1 | 1, mid + 1, r, x, y, val));
  }
  void update(int pos, int val) {
    update(1, 1, n, pos, val);
  }
  int get(int x, int y , int val) {
    return get(1, 1, n, x, y, val);
  }
} st;
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);
  st = segment_tree(n);
  st.update(1, 0);
  
  for(int i = 1; i <= q; ++i) {
    if(!op[i]) {
      st.update(tin[qx[i]], dep[qx[i]]);
    }
    else {
      int u = qx[i], v = qy[i];
      debug(tin[v], tout[v], dep[u]);
      cout << st.get(tin[v], tout[v], dep[u]) << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  solve();

  return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 36692 KB Output is correct
2 Correct 25 ms 36956 KB Output is correct
3 Correct 26 ms 37208 KB Output is correct
4 Correct 30 ms 37464 KB Output is correct
5 Correct 25 ms 36704 KB Output is correct
6 Correct 26 ms 36952 KB Output is correct
7 Correct 28 ms 37208 KB Output is correct
8 Correct 31 ms 37476 KB Output is correct
9 Correct 24 ms 36704 KB Output is correct
10 Correct 24 ms 36952 KB Output is correct
11 Correct 25 ms 37232 KB Output is correct
12 Correct 25 ms 37572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 36692 KB Output is correct
2 Correct 25 ms 36956 KB Output is correct
3 Correct 26 ms 37208 KB Output is correct
4 Correct 30 ms 37464 KB Output is correct
5 Correct 25 ms 36704 KB Output is correct
6 Correct 26 ms 36952 KB Output is correct
7 Correct 28 ms 37208 KB Output is correct
8 Correct 31 ms 37476 KB Output is correct
9 Correct 24 ms 36704 KB Output is correct
10 Correct 24 ms 36952 KB Output is correct
11 Correct 25 ms 37232 KB Output is correct
12 Correct 25 ms 37572 KB Output is correct
13 Correct 32 ms 40020 KB Output is correct
14 Correct 34 ms 43864 KB Output is correct
15 Correct 38 ms 48216 KB Output is correct
16 Correct 47 ms 51804 KB Output is correct
17 Correct 30 ms 39768 KB Output is correct
18 Correct 34 ms 43608 KB Output is correct
19 Correct 49 ms 47704 KB Output is correct
20 Correct 41 ms 51548 KB Output is correct
21 Correct 29 ms 39768 KB Output is correct
22 Correct 35 ms 43608 KB Output is correct
23 Correct 39 ms 47700 KB Output is correct
24 Correct 43 ms 51536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 621 ms 524288 KB Output is correct
2 Runtime error 593 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 36692 KB Output is correct
2 Correct 25 ms 36956 KB Output is correct
3 Correct 26 ms 37208 KB Output is correct
4 Correct 30 ms 37464 KB Output is correct
5 Correct 25 ms 36704 KB Output is correct
6 Correct 26 ms 36952 KB Output is correct
7 Correct 28 ms 37208 KB Output is correct
8 Correct 31 ms 37476 KB Output is correct
9 Correct 24 ms 36704 KB Output is correct
10 Correct 24 ms 36952 KB Output is correct
11 Correct 25 ms 37232 KB Output is correct
12 Correct 25 ms 37572 KB Output is correct
13 Correct 32 ms 40020 KB Output is correct
14 Correct 34 ms 43864 KB Output is correct
15 Correct 38 ms 48216 KB Output is correct
16 Correct 47 ms 51804 KB Output is correct
17 Correct 30 ms 39768 KB Output is correct
18 Correct 34 ms 43608 KB Output is correct
19 Correct 49 ms 47704 KB Output is correct
20 Correct 41 ms 51548 KB Output is correct
21 Correct 29 ms 39768 KB Output is correct
22 Correct 35 ms 43608 KB Output is correct
23 Correct 39 ms 47700 KB Output is correct
24 Correct 43 ms 51536 KB Output is correct
25 Correct 621 ms 524288 KB Output is correct
26 Runtime error 593 ms 524288 KB Execution killed with signal 9
27 Halted 0 ms 0 KB -