Graph Theory37 sections · 1633 units
Open in Course

Path Updates

(Modifying all nodes on path)

Some problems ask you to add xx to all nodes on a path. Use a lazy propagation segment tree to handle range updates efficiently. During the path walk, instead of querying each chain segment, you update it with a range update operation. This still takes O(logn)O(\log n) segments times O(logn)O(\log n) per update, giving O(log2n)O(\log^2 n) total.

The segment tree must support both range updates and range queries with lazy propagation. Without lazy propagation, range updates would take O(n)O(n) time, defeating the purpose.

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