Tree problem

Revision en2, by yoshi_likes_e5, 2025-03-19 04:22:17

Given a tree, 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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English yoshi_likes_e5 2025-03-19 04:23:48 19 Tiny change: 'ven a tree, each nod' -> 'ven a tree rooted at node $1$, each nod'
en2 English yoshi_likes_e5 2025-03-19 04:22:17 1 Tiny change: 'te the sets of nodes ' -> 'te the set of nodes '
en1 English yoshi_likes_e5 2025-03-19 04:21:08 376 Initial revision (published)