Luo Gu $ P $ 3241 shop $ [HNOI2015] $ Chairman tree / dotted rule

Positive Solutions: Chairman of the tree / dynamic point divide and conquer

Report problem solving:

Portal!

$ Umm $ starch, then I will not, if the dynamic $ QAQ $ ,,, so write down the tree explanations Chairman Aung $ QwQ $

Subject to the effect that, given a tree, the tree has a value at each point, then there are a number of query, query given every three values, $ (u, l, r) $, represents the size evaluation in $ [l, r] of all points within the range of $ $ $ point distance U and the number is

If you do not consider the $ [l, r] $ limits, just say, there are a number of inquiries, each given a $ u $, ask all the trees to $ u $ from the point of, how do $ QwQ $?

Consider a fixed point root $ rt $, a pretreatment each node to the root node from $ dis $, is not difficult to think of the answer, $ ans = \ sum_ {i = 1} ^ {n} dis_ {i} + n \ cdot dis_ {u} -2 \ cdot \ sum_ {i = 1} ^ {n} dis_ {lca (u, i)} $, quite obviously not to be construed hot QAQ $ $

It is apparent that as long as quickly obtain $ \ sum_ {i = 1} ^ {n} dis_ {lca (u, i)} $ $ QwQ $ like duck

Consider the root node of the path to each node $ U $ this chain will be taken into account for statistics to $ num_ {i} $, then the $ \ $ SUM will equal $ \ sum num_ {i} \ cdot dis_ {i} $

About the $ num $, can be considered in the tree section, go up for each point on the road after you $ num ++ $

Then consider the $ [l, r] $ limit, so he then sets a President tree that hot $ QwQ $ Eau

Write a little hasty ,,, but do not want to write spicy $ QAQ $, so children have time to lie $ QAQ $ write $ QAQ $

Guess you like

Origin www.cnblogs.com/lqsukida/p/11010359.html