Sparse table

Choose an interval and find its smallest number. The array stays fixed between queries.

Rows store minima for blocks of length 1, 2, 4, and so on. Two adjacent halves give the minimum of a larger block.

Take equal-length blocks at the two ends of the query. They can overlap because repeating a number does not change the minimum.

Preprocessing uses O(n log n) time and space. Each subsequent query takes O(1).