Time limit: 2s
Memory limit: 128MB
Input:
Output:
Task
You are given an array with integers. Let be the minimum value in the subarray , and the maximum value in the subarray . You are also given queries, for the query you are required to count the number of pairs , where and .
Input data
The first line of the input contains two integers and . The second line contains integers, . The next lines describe the queries, the of them contains two integers .
Output data
The output will consist of lines, the line containing the answer to the query.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
1 | 9 | |
2 | 23 | |
3 | 31 | The test cases are randomly generated. |
4 | 37 | No additional constraints. |
Example 1
stdin
7 5
3 5 3 4 2 1 5
2 5
3 5
1 2
2 4
2 4
stdout
2
5
1
2
2
Example 2
stdin
15 10
7 9 2 13 12 13 11 13 13 13 10 5 13 7 2
5 13
7 13
11 13
5 10
7 13
2 9
7 9
2 9
11 13
11 13
stdout
25
1
15
1
1
2
1
2
15
15