#K55387. Maximum Crop Growth Rate Queries

    ID: 29964 Type: Default 1000ms 256MiB

Maximum Crop Growth Rate Queries

Maximum Crop Growth Rate Queries

You are given an array representing the growth rates of crops and a series of queries. Each query consists of two 1-indexed integers L and R. For each query, you need to find the maximum growth rate in the subarray from index L to index R (inclusive).

The task is to process each query and output the maximum value within the specified range. Mathematically, for a query with indices (L) and (R), you need to compute [ \max_{L \leq i \leq R} B_i ] where (B_i) is the growth rate at position (i).

inputFormat

The input is read from standard input (stdin) and follows this format:

  1. The first line contains two integers (M) and (Q) representing the number of crops and the number of queries respectively.
  2. The second line contains (M) integers representing the crop growth rates.
  3. The next (Q) lines each contain two integers (L) and (R) indicating the range of the query (1-indexed).

outputFormat

For each query, output the maximum growth rate within the specified range on a new line to standard output (stdout).## sample

6 3
3 1 4 1 5 9
2 4
1 6
5 6
4

9 9

</p>