Stage 1 · Code
Advanced Data Structures
Segment Tree
Range queries and point updates with lazy propagation.
Segment Tree Structure
Segment tree is a binary tree where each node represents an interval. Root = [0, n-1]. Leaves = single elements. Internal node = merge of children. Stored in array of size 4n. Index 1 = root, left child = 2*i, right = 2*i+1.
Lazy Propagation
For range updates (e.g., add val to [L,R]). Store pending updates in lazy array. Push down only when needed (before querying children or updating further).
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.