Miscellaneous [Title] [CodeForces 1172E] Nauuo and ODT mouth [LCT] [Hu]

Description

Gives a tree of n nodes, each color dot has a 1 to n,

There operation m times, each time modifying the operating point of a color
to be answered in the tree after each operation \ (n ^ 2 \) number of types of color paths and each path passes.

\(n,m<=400000\)

Solution

A very interesting routine

First, we calculate the contribution of each color individually, for each color set of points considered separately, at least we need to calculate the number of paths through which pieces of a point.
N is anti difficult, consider a point number calculated path through the article did not, that is, the point set by deleting the remaining size of the square block and communicating.

Consider a model
for each color had a black and white tree, needs to support a color flip In a tree, find the size of the block and communicating the white square.
N is the total number of black spots

If there is only one tree, that do good, white to maintain direct communication with a block of the LCT, for each point to open a virtual point connected to the son.
But the total number of white point here is \ (O (n ^ 2) \) of

Original solution to a problem given such a sophisticated approach. (Translation solution to a problem again)
To set up a root

We maintain communication with all of the black block, the father shallowest point of each block is referred to as a black communication vertex communication block (for the number of roots we open a node 0), the vertex must be clearly white.

LCT, we will all nodes within the same vertex seen as a communication block, in fact they are not necessarily connected.

Now for two values are recorded for each node, a sub-tree is the size of the continuous blocks, a sub-tree is the square of the size and all the sons.
The obvious answer is the second value and all vertices.

When this color inversion, we only need to discuss this point is the black point or white point, black point, then to cut his father, this information is clearly the same point, but the point will become the apex, updating the answer.

White point, then to link his father, became father vertex case, the information point is not changed, only the modified value of the parent node.

We have for each color in a time sequence of operations run again, since the total number of operations is \ (O (m) \) , so that a total number of points need to use the \ (O (n + m) \) of

I'm not going to write this question, you can feel the specific operation of each color again, and then retreated to the initial state of one color, so the total number of operations is still \ (O (n + m) \) it is.

The total time complexity \ (O ((n + m ) \ log n) \)

Reproduced in: https: //www.cnblogs.com/BAJimH/p/11035454.html

Guess you like

Origin blog.csdn.net/weixin_34406796/article/details/93704765