QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 2048 MB Points totaux : 100

#3867. 天线

Statistiques

在一条直线上有 $n$ 个等间距的天线,编号从 $1$ 到 $n$。每个天线都有一个功率等级,第 $i$ 个天线的功率为 $p_i$。

第 $i$ 个天线和第 $j$ 个天线可以直接通信,当且仅当它们的距离不超过它们功率的最小值,即 $|i - j| \le \min(p_i, p_j)$。在两个这样的天线之间直接发送一条消息需要 $1$ 秒。

求将消息从天线 $a$ 发送到天线 $b$ 所需的最短时间,过程中可以使用其他天线作为中继。

输入格式

每个测试包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 100\,000$),表示测试用例的数量。接下来是 $t$ 个测试用例的描述。

每个测试用例的第一行包含三个整数 $n, a, b$ ($1 \le a, b \le n \le 200\,000$),分别表示天线数量、起始天线编号和目标天线编号。

第二行包含 $n$ 个整数 $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$),表示各天线的功率。

所有测试用例的 $n$ 之和不超过 $200\,000$。

输出格式

对于每个测试用例,输出将消息从 $a$ 发送到 $b$ 所需的秒数。可以证明,在题目给定的约束条件下,总是可以发送消息。

样例

样例输入 1

3
10 2 9
4 1 1 1 5 1 1 1 1 5
1 1 1
1
3 1 3
3 3 1

样例输出 1

4
0
2

说明

在第一个测试用例中,我们需要将消息从天线 $2$ 发送到天线 $9$。一种需要 $4$ 秒的通信序列(这是最短时间)如下:

  • 在 $1$ 秒内,我们将消息从天线 $2$ 发送到天线 $1$。这是可能的,因为 $|2 - 1| \le \min(1, 4) = \min(p_2, p_1)$。
  • 在 $1$ 秒内,我们将消息从天线 $1$ 发送到天线 $5$。这是可能的,因为 $|1 - 5| \le \min(4, 5) = \min(p_1, p_5)$。
  • 在 $1$ 秒内,我们将消息从天线 $5$ 发送到天线 $10$。这是可能的,因为 $|5 - 10| \le \min(5, 5) = \min(p_5, p_{10})$。
  • 在 $1$ 秒内,我们将消息从天线 $10$ 发送到天线 $9$。这是可能的,因为 $|10 - 9| \le \min(5, 1) = \min(p_{10}, p_9)$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.