最低值范围范围、低值

2023-09-11 22:58:08 作者:沧桑过后正年轻

我想找到在一定范围内的最低值。 我必须每次迭代数组或有任何动态的方法?

I would like to find the lowest value in some range. Do I have to iterate array each time or is there any dynamic method?

可以说我有输入数组:

index: 0 1 2 3 4 5 6 7
value: 1 4 6 1 6 7 2 3

然后我不得不选择在最小范围< A,B>(含)。例如:

and then I have to choose smallest in range < a,b > (inclusive). For example:

min(0,7) = 1
min(0,2) = 1
min(4,6) = 2
min(1,2) = 4

林感兴趣的是最快的解决方案,这将是最好的得到的结果在一定的时间。

Im interested in the fastest solution, it would be the best to get the results in constant time.

阵列将不会在此期间被改变。

Array won't be changed in meantime.

推荐答案

如果您打算在同一组数字来执行多个查询,那么你将要构建的笛卡尔树。

If you are going to perform multiple queries over the same set of numbers then you will want to construct a Cartesian Tree.

笛卡尔树木可以用作一个有效的数据结构用于范围最小的查询,涉及该要求在原始序列的连续亚序列中的最小值查询一个范围搜索问题的一部分。

Cartesian trees may be used as part of an efficient data structure for range minimum queries, a range searching problem involving queries that ask for the minimum value in a contiguous subsequence of the original sequence.

正如文章说,该查询可以在固定时间进行。

As the article says, the queries can be performed in constant time.