Graph Theory37 sections · 1633 units
Open in Course

Path Queries II - Update Algorithm

(Change one node)

For an update query (s,x)(s, x), find pos[s], the position of node ss in the flattened array. Update the segment tree at that position to xx. Since ss belongs to exactly one chain, this is a single segment tree point update. The update takes O(logn)O(\log n) time, touching O(logn)O(\log n) nodes in the segment tree.

The segment tree automatically propagates the change up to maintain range maximums. You do not need to update anything else manually. The chain structure remains unchanged.

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