CF1662F.Antennas

普及/提高-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn equidistant antennas on a line, numbered from 11 to nn. Each antenna has a power rating, the power of the ii-th antenna is pip_i.

The ii-th and the jj-th antenna can communicate directly if and only if their distance is at most the minimum of their powers, i.e., ∣i−j∣≤min⁡(pi,pj)|i-j| \leq \min(p_i, p_j). Sending a message directly between two such antennas takes 11 second.

What is the minimum amount of time necessary to send a message from antenna aa to antenna bb, possibly using other antennas as relays?

一条直线上有 nn 个等距排列的天线,编号从 11 到 nn。每个天线有一个功率值,第 ii 个天线的功率为 pip_i。

当且仅当两个天线之间的距离不超过它们功率的最小值时,第 ii 个天线与第 jj 个天线才能直接通信,即满足 ∣i−j∣≤min⁡(pi,pj)|i-j| \leq \min(p_i, p_j)。在满足该条件的任意两个天线之间直接发送一条消息耗时 11 秒。

请问:从天线 aa 向天线 bb 发送一条消息(允许经由其他天线中继)所需的最短时间是多少?

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤100 0001\le t\le 100\,000) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains three integers nn, aa, bb (1≤a,b≤n≤200 0001 \leq a, b \leq n \leq 200\,000) — the number of antennas, and the origin and target antenna.

The second line contains nn integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤n1 \leq p_i \leq n) — the powers of the antennas.

The sum of the values of nn over all test cases does not exceed 200 000200\,000.

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

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

每个测试用例的第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \dots, p_n(1≤pi≤n1 \leq p_i \leq n),表示各天线的功率。

所有测试用例中 nn 的总和不超过 200 000200\,000。

输出格式

For each test case, print the number of seconds needed to trasmit a message from aa to bb. It can be shown that under the problem constraints, it is always possible to send such a message.

对于每个测试用例,输出从节点 aa 向节点 bb 传输一条消息所需的秒数。在本题的约束条件下,可以证明总能成功发送该消息。

输入输出样例

  • 输入#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

说明/提示

In the first test case, we must send a message from antenna 22 to antenna 99. A sequence of communications requiring 44 seconds, which is the minimum possible amount of time, is the following:

  • In 11 second we send the message from antenna 22 to antenna 11. This is possible since ∣2−1∣≤min⁡(1,4)=min⁡(p2,p1)|2-1|\le \min(1, 4) = \min(p_2, p_1).
  • In 11 second we send the message from antenna 11 to antenna 55. This is possible since ∣1−5∣≤min⁡(4,5)=min⁡(p1,p5)|1-5|\le \min(4, 5) = \min(p_1, p_5).
  • In 11 second we send the message from antenna 55 to antenna 1010. This is possible since ∣5−10∣≤min⁡(5,5)=min⁡(p5,p10)|5-10|\le \min(5, 5) = \min(p_5, p_{10}).
  • In 11 second we send the message from antenna 1010 to antenna 99. This is possible since ∣10−9∣≤min⁡(5,1)=min⁡(p10,p9)|10-9|\le \min(5, 1) = \min(p_{10}, p_9).

在第一个测试用例中,我们必须将消息从天线 22 发送到天线 99。以下是一条耗时 44 秒的消息传递序列,该耗时为可能的最短时间:

  • 在 11 秒内,我们将消息从天线 22 发送至天线 11。这是可行的,因为 ∣2−1∣≤min⁡(1,4)=min⁡(p2,p1)|2-1|\le \min(1, 4) = \min(p_2, p_1)。
  • 在 11 秒内,我们将消息从天线 11 发送至天线 55。这是可行的,因为 ∣1−5∣≤min⁡(4,5)=min⁡(p1,p5)|1-5|\le \min(4, 5) = \min(p_1, p_5)。
  • 在 11 秒内,我们将消息从天线 55 发送至天线 1010。这是可行的,因为 ∣5−10∣≤min⁡(5,5)=min⁡(p5,p10)|5-10|\le \min(5, 5) = \min(p_5, p_{10})。
  • 在 11 秒内,我们将消息从天线 1010 发送至天线 99。这是可行的,因为 ∣10−9∣≤min⁡(5,1)=min⁡(p10,p9)|10-9|\le \min(5, 1) = \min(p_{10}, p_9)。

输入解题思路,AI测评打分。不知道怎么写?

首页