To query range :
Find the largest power of 2 that fits:
Take of two overlapping ranges of length :
- One starting at :
- One ending at :
def query(l, r):
length = r - l + 1
k = int(log2(length))
return min(st[l][k], st[r - (1 << k) + 1][k])
These two ranges cover completely, possibly overlapping in the middle. Since is idempotent, overlapping is fine.
Time: per query (with precomputed values).