QOJ.ac

QOJ

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

#2418. 反转卡组

Statistiques

Elf by LadyofHats via Wikimedia Commons, public domain

作为流行集换式卡牌游戏《Numinous Wilds: the Elven Reign Chronicles (NWERC)》的忠实粉丝,你拥有一大批精心按稀有度整理好的卡牌。一天,你发现有人动过你的收藏,导致一些卡牌的顺序乱了。最自然的怀疑对象当然是你的弟弟 Billy,他被严令禁止触碰你的卡牌。经过几分钟的盘问,Billy 承认他确实从牌堆中间拿走了一段连续的卡牌,但他发誓他把它们放回去时顺序和原来一模一样。你怀疑 Billy 因为年纪太小,可能只是不小心把拿走的卡牌顺序颠倒了。现在,你想验证你的理论,并确定是否能找到 Billy 拿走的那一叠卡牌。

是否可以通过翻转一段连续的卡牌,将所有卡牌按稀有度非递减的顺序排列?

输入格式

  • 第一行包含一个整数 $n$ ($1 \le n \le 10^6$),表示你收藏的卡牌数量。
  • 第二行包含 $n$ 个整数 $v_1, \dots, v_n$ ($1 \le v_i \le 10^9$,对于所有 $i$),表示当前卡牌稀有度的顺序。

输出格式

如果可以通过翻转列表中的恰好一段连续子序列使卡牌有序,则输出该子序列的起始和结束下标(从 1 开始计数)。否则,输出 impossible。如果存在多个有效的解,你可以输出其中任意一个。

样例

输入格式 1

7
10 13 19 19 15 14 20

输出格式 1

3 6

输入格式 2

6
9 1 8 2 7 3

输出格式 2

impossible

输入格式 3

3
1 2 3

输出格式 3

2 2

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.