Luo Gu P3258 squirrel new home explanations

Face questions

This question is seemingly plus metaphysics optimization violence can be AC?

 

Below is a positive solution:

  1. Chain tree split:

   We all put a candy in between u to v, u can squirrel it is home to several candy v are increased by one. Each time the a [i] to a [i + 1] (a is the array access order) adding a node, the tree can be used to maintain chain split. Query only need to check the weight of each point on it. (Looks like the problem than the tree section of the board is also the board?)

 2. tree check points: the focus here! (Knock blackboard !!!)

        Meaning of the questions in this question is the number of points after all statistically path.

   Known source array a [i] represents the weight of each dot point, provided the difference array s [i] = a [i] -sum (a [j]) (j for each i, son directly connected);

      b [i] for the leaf node is exactly the right little a [i];

   For any node k, a [k] = k is a subtree root to all s [i] and the sum.

   S disposed difference array [], for each operation,

    s[u]++;

    s[v]++;

    s[LCA(u,v)]--;

    s[fa[LCA(u,v)]]--;

      This is the case right to the point, if it is the right side, just need a point to the right side of his father's assigned its own right as a point,

      Then the situation as a point right to do just fine, details need to handle it.

 

   

 

Guess you like

Origin www.cnblogs.com/kamimxr/p/11279041.html