#P15130. [ROIR 2026] 超级跳跃
[ROIR 2026] 超级跳跃
Problem Description
In the computer game "Super Jump", the hero jumps between the peaks of mountains. The goal is to reach the position with a flag and complete the level there.
The mountain range in the game consists of serrated peaks arranged consecutively. The -th peak is located at position and has height . For any , the hero can jump in a straight line from peak to peak if the flight path does not meet any other peak. More formally, there is no such that and the вершина (dingdian) of the -th peak—the point with coordinates —is strictly higher than the line segment connecting and .
"Beat AI" is training a neural network to control the hero in the game. To create training data, they need to answer multiple queries: for a pair of indices (), determine the minimum number of jumps required for the hero to reach peak starting from peak .
Input Format
The first line of the input contains a number () — the number of peaks.
The second line contains numbers: () — the heights of the peaks.
The third line contains a number () — the number of queries.
Each of the next lines contains two numbers () — the parameters of each query.
Output Format
For each query, output a non-negative integer on a separate line — the minimum number of jumps required.
8
5 3 4 3 6 2 1 4
3
1 8
2 7
4 4
2
2
0
Hint
Sample Explanation
We analyze the second query in the sample. The path for the hero from peak 2 to peak 7 can look as follows:
:::align{center}
:::
He will visit peaks 2, 5, and 7 in order, making a total of two jumps.
Scoring Rules
| Subtask | Points | Additional Constraints | Required Subtasks |
|---|---|---|---|
| 1 | 9 | ||
| 2 | 1 | ||
| 3 | 14 | ||
| 4 | 21 | There exists such that for all , | |
| 5 | 27 | 1, 2 | |
| 6 | 20 | No additional constraints | 1–5 |
Translated by ChatGPT 5