Data Structures19 sections · 729 units
Open in Course

Problem - Static Range Min

Many queries, no updates

Given a static array of nn integers and qq queries, find the minimum in each queried range. You're solving the canonical Sparse Table problem.

With q=106q = 10^6 queries, the O(1)O(1) query time is needed. Compare:

  • Naive: O(nq)O(nq) . Too slow
  • Segment Tree: O(n+qlogn)O(n + q \log n)
  • Sparse Table: O(nlogn+q)O(n \log n + q) For n=105n = 10^5 and q=106q = 10^6:
  • Segment Tree: ~2010620 \cdot 10^6 operations
  • Sparse Table: ~10610^6 operations (after preprocessing) Constraints: nn up to 10510^5, qq up to 10610^6.