Skip to main content

Mixed Path Operations

Challenge on lesson: Checkpoint — Path Queries with HLD

CHALLENGE
Difficulty: advanced+25 XP

**Bài toán.** A rooted tree (root 1): n on line 1; parents par[2..n] on line 2 (par[v] < v); vertex values val[1..n] on line 3; q on line 4; then q operations: "1 u v x" — add x to every vertex on the path u..v; "3 u v x" — assign x to every vertex on the path u..v; "2 u v" — print the MAXIMUM value on the path u..v, one per line. **Constraints:** 1 ≤ n, q ≤ 200 000; |val|, |x| ≤ 10^9. HLD over chain positions with a three-tag lazy tree (assign kills the pending add); the walk must handle the final same-chain segment even when pos[u] > pos[v].

Back to lesson: Checkpoint — Path Queries with HLD