#d11403. 不降子数组游戏
不降子数组游戏
Non-decreasing Subarray Game
Problem Description
Yuto and Platina are about to play a non-decreasing-subarray game.
Specifically, given an array of length , and bound indices and .
Yuto first chooses a number in and shows it to Platina.
Then Platina also chooses a number in .
Suppose Yuto chooses and Platina chooses .
The score of this round is the number of non-decreasing subarrays of ( denotes the new array formed by the contiguous segment of from index to ).
Note: a subarray of array is obtained by deleting some (possibly empty) prefix and suffix of .
Yuto wants the score to be as small as possible, while Platina wants it as large as possible.
They will play on the array times. For each game, output the final score.
Input Format
The first line contains a positive integer , the length of array .
The next line contains positive integers, representing .
The third line contains a positive integer , the number of games.
The next lines each contain two positive integers and .
For all data: , , and .
Output Format
For each game, output one positive integer: the final score of the game.
Sample Input
8
7 10 3 1 9 5 5 2
5
1 5
2 2
5 8
1 8
3 5
Sample Output
4
1
4
7
3