Task
Chimmy has an array of integers and queries of the form , where for each query Chimmy wants to know, when traversing the subarray from position to position , how many times the running maximum changes. Chimmy, not knowing how to program, asks for your help for points!
Input data
The program reads from the keyboard the numbers and , after which it reads numbers representing the array.
The next lines will contain two numbers and , as described in the statement.
Output data
The answer for each query will be displayed on a separate line.
Restrictions and clarifications
- It is recommended to use fastio.
- The numbers in the array can be represented on signed 32-bit integers.
- Traversals from to will not always be from left to right. For example, if and , the indices will be traversed in the order .
Example
stdin
7 5
4 6 1 3 5 2 8
3 7
4 6
1 7
6 1
5 5
stdout
4
2
3
3
1
Explanation
In the subarray , the maximum changes times (, , , ).
In the subarray , the maximum changes times (, ).
In the subarray , the maximum changes times (, , ).
In the subarray , the maximum changes times (, , ) (the subarray was traversed in reverse).
In the subarray , the maximum only changes once ().