Logo
(追記) (追記ここまで)

25061번 - Antennas 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 2048 MB109555155.435%

문제

There are $n$ equidistant antennas on a line, numbered from 1ドル$ to $n$. Each antenna has a power rating, the power of the $i$-th antenna is $p_i$.

The $i$-th and the $j$-th antenna can communicate directly if and only if their distance is at most the minimum of their powers, i.e., $|i - j| ≤ \min{(p_i, p_j)}$. Sending a message directly between two such antennas takes 1ドル$ second.

What is the minimum amount of time necessary to send a message from antenna $a$ to antenna $b,ドル possibly using other antennas as relays?

입력

Each test contains multiple test cases. The first line contains an integer $t$ (1ドル ≤ t ≤ 100,000円$) — the number of test cases. The descriptions of the $t$ test cases follow.

The first line of each test case contains three integers $n,ドル $a,ドル $b$ (1ドル ≤ a, b ≤ n ≤ 200,000円$) — the number of antennas, and the origin and target antenna.

The second line contains $n$ integers $p_1,ドル $p_2,ドル $\dots,ドル $p_n$ (1ドル ≤ p_i ≤ n$) — the powers of the antennas. The sum of the values of $n$ over all test cases does not exceed 200ドル,000円$.

출력

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

제한

예제 입력 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

Explanation of sample 1.

In the first test case, we must send a message from antenna 2ドル$ to antenna 9ドル$. A sequence of communications requiring 4ドル$ seconds, which is the minimum possible amount of time, is the following:

  • In 1ドル$ second we send the message from antenna 2ドル$ to antenna 1ドル$. This is possible since $|2 - 1| ≤ \min{(1, 4)} = \min{(p_2, p_1)}$.
  • In 1ドル$ second we send the message from antenna 1ドル$ to antenna 5ドル$. This is possible since $|1 - 5| ≤ \min{(4, 5)} = \min{(p_1, p_5)}$.
  • In 1ドル$ second we send the message from antenna 5ドル$ to antenna 10ドル$. This is possible since $|5 - 10| ≤ \min{(5, 5)} = \min{(p_5, p_{10})}$.
  • In 1ドル$ second we send the message from antenna 10ドル$ to antenna 9ドル$. This is possible since $|10 - 9| ≤ \min{(5, 1)} = \min{(p_{10}, p_9)}$.

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2021-2022 I번

  • 문제를 만든 사람: Simon Mauras
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /