| INOI 2025 |
|---|
| Finished |
Given a constraint array $$$A$$$ of length $$$N$$$, we generate a new integer array $$$B$$$ of length $$$N$$$ satisfying the following conditions:
Let $$$f(A)$$$ denote the minimum possible value of the last element of $$$B$$$ for a valid array $$$B$$$.
You will be given queries $$$L$$$ and $$$R$$$, and you need to answer $$$f(A[L, R])$$$ where $$$A[L, R]$$$ denotes the subarray $$$[A_L, A_{L + 1}, ..., A_R]$$$. That is, you need to answer the minimum value of the last element of $$$B$$$ possible if only the $$$L$$$-th to the $$$R$$$-th indices of $$$A$$$ were present.
There are multiple test cases in each file, and thus you will be given an input parameter $$$T$$$, denoting that you have to solve $$$T$$$ test cases.
The first line of input contains $$$T$$$ - the number of test cases.
The first line of each test case contains $$$N$$$ and $$$Q$$$ - the size of the array $$$A$$$ and the number of queries respectively.
The second line of each test case contains $$$N$$$ integers - $$$A_1, A_2, ..., A_N$$$
The $$$j$$$-th of the next $$$Q$$$ lines contains $$$L_j$$$ and $$$R_j$$$ - the parameters of the $$$j$$$-th query.
For each test case, output $$$Q$$$ integers on a single line, $$$f(A[L_j, R_j])$$$ for each query.
Constraints
It is guaranteed that
Subtasks
The special constraint whole array means that $$$Q = 1, L_1 = 1, R_1 = N$$$, i.e. there is only one query which covers the whole array.
32 12 11 24 21 2 3 41 42 46 52 1 1 3 2 11 62 54 63 35 5
2 5 1 3 3 2 2 1
Test Case 1 : This is a query on the whole array. $$$A = [2, 1]$$$ and we choose $$$B = [1, 2]$$$ which satisfies all conditions, while minimizing the last element value of $$$2$$$. It can be proven it is impossible to achieve a smaller value.
Test Case 2 : In the first query, the query is again of the whole array, $$$A = [1, 2, 3, 4]$$$ and we choose $$$B = [5, 5, 5, 5]$$$ which satisfies all conditions and minimizes the last element value of $$$5$$$.
In the second query, we work with the subarray $$$A = [2, 3, 4]$$$ instead, and we can choose $$$B = [1, 1, 1]$$$ here.
| Name |
|---|


