9.13 infected your color

The meaning of problems

Given a weighted rooted tree, remember \ (LCA (u, v) \) is \ (u, v \) most recent common ancestor, \ (DIS (U) \) represents the root to \ (u \ ) distance

Each node can be black or white, the original color to white nodes

There \ (m \) operations, the operation is divided into two

  • The nodes \ (X \) dyed black

  • All black dots formed mind set for \ (S \) and a node \ (X \) , the following equation is obtained the value of
    \ [\ sum_ {y \ in S} F (dis (LCA (u, v)) ) \]
    where the function \ (F. \) is defined as
    \ [F (x) = \ sum_ {i = 1} ^ xi ^ k \]


solution

Violence is simple strike \ (x \) and \ (S \) midpoint of \ (LCA \) and calculated

We consider a different perspective, consider \ (LCA \) contributions

\ (X \) and \ (S \) midpoint \ (the LCA \) must lie by the \ (X \) on that one path to the root of the tree

For each edit operation, we made \ (X \) to the root of this path are marked with markers (i.e., plus a)

Each query to query \ (x \) mark to the sum to the root path

In order to ensure the complexity, we treated a tree split chain

Because at the time of modification, we will \ (x \) to the root of a mark on the whole have added a path, but the point \ (x \) is , truly meaningful only \ (LCA (x, S_i ) \) that a mark on, so from the root to \ (\) fa [(x , S_i) LCA] mark on the fact is not legal

To the outcome of this issue, we can put the right value to each node \ (F (dis (x) ) - F (dis (fa [x])) \)

Such demand will only be counted out and contribute to the legitimate mark

Why are you doing this? This is actually a differential operation

The difference array \ ([l, r] \ ) sections are coupled \ (1 \) , the prefix and find the significance of the fact \ (A_L \) at the plus \ (1 \)

Also note that \ (F \) function to use linear sieve pretreatment


Code

Not to fight, when to fix

Guess you like

Origin www.cnblogs.com/VeniVidiVici/p/11519956.html