QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#16718. Altitude

统计

在一款名为 “Take Them All” 的新电脑游戏中,玩家控制一架向前飞行的无人机,并且必须通过沿途的所有检查点。每个检查点都位于某个高度(可能为负数),玩家必须调整无人机的高度才能通过该检查点。

给你一个由 $n$ 个互不相同的整数组成的序列 $a_1, a_2, \dots, a_n$。第 $i$ 个检查点位于高度 $a_i$。关卡是环形的:索引为 $n$ 的检查点后面紧接着索引为 $1$ 的检查点。如果索引三元组(不一定互不相同)$i$、$j$ 和 $k$ 满足 $a_i < a_j > a_k$,则称其为 tricky 三元组

三元组 $i$、$j$ 和 $k$ 的长度定义为无人机从 $i$ 飞到 $j$ 再从 $j$ 飞到 $k$ 所需要飞过的相邻检查点之间路段的最小数量。正式地,我们定义 $d_1$ 为:若 $j > i$ 则为 $j - i$,若 $j \le i$ 则为 $n - (i - j)$;定义 $d_2$ 为:若 $k > j$ 则为 $k - j$,若 $k \le j$ 则为 $n - (j - k)$。那么,三元组 $i$、$j$ 和 $k$ 的长度等于 $d_1 + d_2$。

本题的目标是找到一个长度最小的 tricky 三元组。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 100\,000$)—— 检查点的数量。

第二行包含检查点高度序列 $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$)。保证所有 $a_i$ 的值互不相同。

输出格式

输出三个整数 $i$、$j$ 和 $k$ ($1 \le i, j, k \le n$),表示长度最小的 tricky 三元组。如果有多个最优解,输出其中任意一个。

样例

输入样例 1

2
20 16

输出样例 1

2 1 2

输入样例 2

4
2 0 1 6

输出样例 2

3 4 1

输入样例 3

5
16 10 20 1 6

输出样例 3

2 3 4

说明

请注意,对于第二个样例,三元组 1, 4, 3 不是正确答案。该三元组虽然是 tricky 的,但它的长度大于三元组 3, 4, 1 的长度。

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.