题目链接:HDU 5443
Problem Description
In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with $a_1,a_2,a_3,…,a_n$ representing the size of the water source. Given a set of queries each containing $2$ integers $l$ and $r$, please find out the biggest water source between $a_l$ and $a_r$.
Input
First you are given an integer $T(T\le 10)$ indicating the number of test cases. For each test case, there is a number $n(0\le n\le 1000)$ on a line representing the number of water sources. $n$ integers follow, respectively $a_1,a_2,a_3,…,a_n$, and each integer is in ${1,…,10^6}$. On the next line, there is a number $q(0\le q\le 1000)$ representing the number of queries. After that, there will be $q$ lines with two integers $l$ and $r(1\le l\le r\le n)$ indicating the range of which you should find out the biggest water source.
Output
For each query, output an integer representing the size of the biggest water source.
Sample Input
1 | 3 |
Sample Output
1 | 100 |
Source
2015 ACM/ICPC Asia Regional Changchun Online
Solution
题意
给定 $n$ 个数,$q$ 个询问,每个询问包含 $l$ 和 $r$,求区间 $[l, r]$ 内的最大值。
思路
ST算法
$RMQ$ 问题。ST 算法模板题。预处理时间 $O(nlogn)$,查询时间 $O(1)$。
Code
1 |
|