##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You know Euler tours for subtrees. HLD handles path queries by decomposing into heavy chains.
(Solving path queries fast)
(Maximum on a path)
Paths cross subtree boundaries
(Break paths into chains)
(Counting descendants)
(Splitting by subtree size)
(Maximal heavy sequences)
(Why paths cross few chains)
(Two paths meet at ancestor)
(Assigning nodes to chains)
(Indexing nodes within chains)
(Top node of each chain)
(Range queries on chains)
(Flatten all chains)
(Walk up to LCA)
(Comparing node depths)
(Jumping to parent)
(Changing a node value)
(Where to store values)
(Finding the meeting point)
(Time and space bounds)
(Computing sizes and parents)
(Building chains)
(Supporting range max)
(Combining chain segments)
(Modifying all nodes on path)
(Sum instead of maximum)
(CSES 1138 path maximum)
(Decompose the tree)
(Store values by position)
(Walk up both sides)
(Change one node)
(Per-query analysis)
(Pseudocode)
(What you learned)
(SPOJ classic HLD problem)
(Store edge weights at nodes)
(Exclude the LCA)
Change edge $i$ to weight $ti$
(Same as vertex version)
(Edge indexing)
(Edge queries via HLD)
(Path queries on trees)
(Updates vs queries)
(Pitfalls to avoid)
Knowledge check
Knowledge check
Knowledge check
(What you learned)