Often you need not the minimum value, but its position.
Store pairs in the sparse table. The merge takes the pair with smaller value (or smaller index to break ties).
def build():
for i in range(n):
st[i][0] = (arr[i], i)
for j in range(1, K):
for i in range(n - (1 << j) + 1):
left = st[i][j-1]
right = st[i + (1 << (j-1))][j-1]
st[i][j] = left if left[0] <= right[0] else right
def query(l, r):
k = LOG[r - l + 1]
left = st[l][k]
right = st[r - (1 << k) + 1][k]
return left if left[0] <= right[0] else right
Returns both the minimum value and its index in .