#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 nn serrated peaks arranged consecutively. The ii-th peak is located at position ii and has height hih_i. For any i<ji < j, the hero can jump in a straight line from peak ii to peak jj if the flight path does not meet any other peak. More formally, there is no kk such that i<k<ji < k < j and the вершина (dingdian) of the kk-th peak—the point with coordinates (k,hk)(k, h_k)—is strictly higher than the line segment connecting (i,hi)(i, h_i) and (j,hj)(j, h_j).

"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 l,rl, r (1≤l≤r≤n1 \leq l \leq r \leq n), determine the minimum number of jumps required for the hero to reach peak rr starting from peak ll.

Input Format

The first line of the input contains a number nn (1≤n≤1051 \leq n \leq 10^5) — the number of peaks.

The second line contains nn numbers: h1,h2,…,hnh_1, h_2, \ldots, h_n (0≤hi≤10120 \leq h_i \leq 10^{12}) — the heights of the peaks.

The third line contains a number qq (1≤q≤1051 \leq q \leq 10^5) — the number of queries.

Each of the next qq lines contains two numbers li,ril_i, r_i (1≤li≤ri≤n1 \leq l_i \leq r_i \leq n) — 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 n,q≤300n, q \leq 300
2 n,q≤5000n, q \leq 5000 1
3 14 hi≤10h_i \leq 10
4 21 There exists kk such that for all ii, li≤k≤ril_i \leq k \leq r_i
5 27 n,q≤5⋅104n, q \leq 5 \cdot 10^4 1, 2
6 20 No additional constraints 1–5

Translated by ChatGPT 5