#P3246. [HNOI2016] 序列
[HNOI2016] 序列
Description
Given a sequence of length : , denoted by . Similarly, () denotes the sequence . If , then is called a subarray of .
Now there are queries. Each query gives two numbers and , where . For each query, find the sum of the minimum values over all subarrays of . For example, given the sequence and the query , , the subarrays of are $a[1 \colon 1], a[2 \colon 2], a[3 \colon 3], a[1 \colon 2], a[2 \colon 3], a[1 \colon 3]$. The sum of their minimum values is .
Input Format
The first line contains two integers and , the sequence length and the number of queries.
The second line contains integers separated by spaces. The -th integer is , the value of the -th element of the sequence.
Each of the next lines contains two integers and , describing a query.
Output Format
For each query, output one line containing the answer.
5 5
5 2 4 1 3
1 5
1 3
2 4
3 5
2 5
28
17
11
11
17
Hint
Constraints: For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号