Data Structures19 sections · 729 units
Open in Course

Problem - Path Queries

HLD in action

Given a tree with nn nodes, each with a value. Process qq queries:

1.1. Update: change the value of node uu to vv

2.2. Query: find the maximum value on the path from uu to vv

Constraints: n,q2105n, q \leq 2 \cdot 10^5. You're solving the classic HLD problem. The tree structure prevents using standard segment trees directly. HLD breaks the tree into chains, each handled by a segment tree. Before reading the solution, think about why sqrt decomposition wouldn't work well here.