[SDOI2016] Game — Solution
Approach
Clearly we need heavy-light decomposition.
For each operation of the form \(a \times dis + b\), add it to the lazy tag. If we run into lazy information that is already there, we only need to think of such an operation as adding a line, and push the lower edge of the lines down to the left and right children. (Compute the lengths to decide whether to push down left or right.) For each node, the lazy addition is the sum of an arithmetic sequence: compute \(b \times subtreeSize + a \times \frac{subtreeSize*(subtreeSize-1)}{2}\).