Блог пользователя Sanat_HUIHUIHUI

Автор Sanat_HUIHUIHUI, история, 18 месяцев назад, По-английски

Hey, I recently participated in ABC308, I thought my approach for solving G was different compared to one in the editorial and what most people used, So I decided to share it (Although I was only able to solve it few mins after the contest ended)

If you want to refer to my code https://atcoder.jp/contests/abc308/submissions/43162433

I basically maintained a segment tree, where the topmost node maintained the answer for the whole array. and to support it I had two nodes who took care of values whose 29th bit is off and 29 th bit is on respectively.

and similarly, these nodes were supported by two nodes, who took care of the numbers that were the same from i to 30th bit and that differed in (i-1)th bit.

I continued it down all the way to the 0th bit.

first clarification, such Segment tree could have O(10^9) nodes and to avoid it I used a dynamic segment tree (aka sparse segment tree to achieve a Space complexity of Q*30)

Key observation for a node and its two child nodes we do not need to take care of the values that occur due to xor of values that are in different nodes since it would have i^th bit on, which would be worse compared to xor any two values within one of the child node because it would have i^th bit off and that is better obviously.

But we sometimes have to consider the xor value due to cross terms, precisely when a node has 2 elements and they differ in (i-1)th bit but are same all the up. since there is only one element in each child node, so answer for each child node is infinity but the answer for the parent node would be xor of 2 values.

Also when a node has >= 3 elements it is guaranteed that one the child node has less than infinity as the answer, due to the pigeonhole hole principle.

then adding and removing any element was easy just regular segment tree stuff.

basically, that's it.

  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

»
18 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Sanat_HUIHUIHUI (previous revision, new revision, compare).

»
18 месяцев назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

I used this solution as well.

This tree is actually a trie on the binary representations of the $$$x$$$ values.

  • »
    »
    18 месяцев назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    True, it is one way to look at things, Dynamic Segment tree, is a binary trie. After all Segment tree is nothing but a binary Tree, so it's dynamic version is basically is dynamic tree aka trie