Data Structures19 sections · 729 units
Open in Course

Range Minimum Query

Min instead of sum

For range minimum queries, precompute blockMin[k]blockMin[k] instead of blockSum[k]blockSum[k]. The query logic is similar:

1.1. Left tail: find min from ll to end of ll's block

2.2. Complete blocks: find min of blockMin[b]blockMin[b] values

3.3. Right tail: find min from start of rr's block to rr Time: still O(n)O(\sqrt{n}) per query. Updates are trickier. If you update arr[i]arr[i] to a smaller value, blockMinblockMin might decrease. If you update to a larger value, you might need to recompute the entire block's minimum.