loj558 "Antileaf's Round" our CPU was attacked

After the exam is over, you can ask questions.

The approach is that link-cut tree maintains subtree information, and does not need to maintain black and white trees.

Here is a heavy chain:

If 4 is the root, then on splay it looks like this:

In splay, the information of the subtree has been calculated, so the answer of this subtree needs to be calculated.

This subtree has 4 parts:

4: tree roots.
1,2,3: Points above the root of the tree.
5,6: Points below the root of the tree.
other: The virtual subtree of the root.

So to simplify:

Obviously the answer needs to be recorded, but what else?

  • 3,4 will be affected by 1,2, so the answer should add the number of black points in 3,4 × the weight in 1,2 and
  • 1 will be affected by 2, so the answer should add the number of black points in 1 × the weight in 2 and
  • Gone. The rest is calculated in the original.

Therefore, it is necessary to remember the number of black points and the sum of the weights of the subtree.

Then it's done.

?

Note that splay has a reverse operation, so you have to remember an inverse answer (crazy,,,), but the answer of the virtual subtree does not need to be reversed.

The code is too long and the link is lost: https://loj.ac/submission/94648

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325099634&siteId=291194637