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

Автор yoshi_likes_e5, история, 8 часов назад, По-английски

Given a tree rooted at node $$$1$$$, each node $$$i$$$ has value $$$a_i$$$, let $$$s(u)$$$ denote the set of nodes in $$$u$$$'s subtree. You should calculate the sum: $$$\sum_u{(XOR_{c\in s(u)}(a_c+d(u,c)))}$$$.

I have reduced the problem to:

  • Add 1 to every number on a segment.

  • Find XOR on a segment.

But I can't think of any DS that solves the problem above. Any help will be appreciated.

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

»
8 часов назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

Segment tree. Note that when we add 1 to a segment, its node will be flipped among 2 values.