Graph Theory37 sections · 1633 units
Open in Course

Reveal - Path Queries II

(Why HLD handles updates)

This problem needs path queries AND updates. LCA cannot handle updates. Euler Tour only works for subtrees.

Heavy-Light Decomposition splits the tree into chains. Each chain is stored in a segment tree. When you query a path from a to b, you decompose it into O(logn)O(\log n) chain segments and query each segment tree.

Updates work the same way: find the chain containing the node, update its segment tree. Total: O(log2n)O(\log^2 n) per operation.

Space complexity is O(n)O(n) for the data structures used.