teacher
Sign in

Sparse Table

Precompute answers for every power-of-two length so that range min, max or gcd on a fixed array takes O(1) per query.

30 minCF 1700–22005 interactive8 problems

The problem

You have a fixed array of n numbers and q queries. Each asks for the minimum of a[l..r]. Nothing ever changes. With n and q near 200,000 or more, you want each query to cost almost nothing.

1 of 9