Practice · 1 of 3
Path Add, Path Max
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; "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 + a lazy range-add/range-max tree: O((n + q)·log² n). The final same-chain segment needs the swap.
Press Submit to check your solution.
Back to lesson: Practice: HLD Trio