USACO 2019 February Contest, Gold
Heavy-Light Decomposition (HLD) allows tree paths from the child to the parent to be expressed as a contiguous subarray. We can then use a segment tree to update and get values in O(log n).
Problem:
- Problem link: http://www.usaco.org/index.php?page=viewproblem2&cpid=921
- Problem solution: http://www.usaco.org/current/data/sol_cowland_gold_feb19.html
Online material that I used: