1799: 区间内分数的最大值

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:110 Solved:18

Description

       学校数据库中存放了大量的学生成绩,张校长给你一个长度为 N 的数列,和 Q 次询问,要你编写一个查询程序,快速求出每一次询问区间内分数的最大值。

Input

输入第一行包含两个整数 N,Q, 分别表示数列的长度和询问的个数。
第二行包含 N 个整数(记为 ai ),依次表示数列的第 i 项。
接下来 Q 行,每行包含两个整数 li, ri,表示查询的区间为 [li,ri]

Output

输出包含 Q行,每行一个整数,依次表示每一次询问的结果。


Sample Input Copy

8 8
99 63 71 87 65 56 70 98
1 6
1 5
2 7
2 6
2 3
4 8
5 7
1 8

Sample Output Copy

99
99
87
87
71
98
70
99

HINT

 lns="http://www.w3.org/1998/Math/MathML">1\le N\le {10}^5lns="http://www.w3.org/1998/Math/MathML">1\le M\le 2\times{10}^6lns="http://www.w3.org/1998/Math/MathML">a_i\in[0,{10}^9]lns="http://www.w3.org/1998/Math/MathML">1\le l_i\le r_i\le N