Test instructions: Find a point I in the tree, and find some points in the tree to form a set, so that the sum of all points in the set of C is not more than M, and li* the number of elements in the collection and the maximum
First, we process the tree out of the DFS sequence and turn the subtree query into an interval query.
Then we found that for a single node, "so that all points in the set of C and not more than M, and the number of elements in the li* set and the largest" can be greedy, that is, the preference of the C small point. (<--This is the Chairman Tree/Weight segment tree/weight-value block work)
But we need to enumerate all the nodes and choose the largest one from them.
Since there is a DFS sequence, then there is no modification of the interval asked. (<--'s work) but in the course of the team transfer, the Chairman Tree/Weight segment Tree Insert/delete cannot withstand. (Of course, the chairman of the tree does not need MO team, also can solve this problem, but this is not the article to introduce) the weight of the block insertion/deletion is O (1), the query is O (sqrt (n)), the total complexity is still O (n*sqrt (n)).
Programming complexity is low and constant is small.
"Dfs sequence" "Mo Team Algorithm" "Weight-value chunking" bzoj2809 [apio2012]dispatching