QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 65536 MB مجموع النقاط: 100 قابلة للهجوم ✓

#6732. 丝带

الإحصائيات

Bytie 的爸爸是一名裁缝。 有一天,当爸爸把 Bytie 独自留在工作室时,Bytie 发现了一条非常漂亮的卷尺。 这实际上是一条包含从 $1$ 到 $n$ 的连续数字的卷尺。 不知怎么的,Bytie 还找到了他爸爸的剪刀……

不幸的是,当爸爸回来时,一切都已经太晚了:Bytie 已经把卷尺剪了几次。 幸运的是,在每一次剪切中,Bytie 都剪下了一段卷尺,将其翻转,然后放回了完全相同的位置。 Bytie 声称他一共进行了 $k$ 次这样的剪切。 例如,如果初始卷尺是 $[1,\,2,\,3,\,4,\,5,\,6]$,而 Bytie 剪下了片段 $[3,\,4,\,5]$ 并将其翻转,卷尺就会变成 $[1,\,2,\,5,\,4,\,3,\,6]$。

请帮助 Bytie 的爸爸,尝试通过 $k$ 次剪切和翻转片段的操作来恢复初始的卷尺。

输入的第一行包含两个整数 $n$ 和 $k$ ($1 \leq n \leq 100\,000$, $0 \leq k \leq 3$),分别表示卷尺上数字的个数以及 Bytie 声称执行的操作次数。 下一行包含 Bytie 的爸爸走进房间时卷尺上的数字:一个包含 $n$ 个整数的序列 $a_i$ ($1 \leq a_i \leq n$)。

输出的第一行应包含一个单词 TAK(波兰语,意为“是”)或 NIE(波兰语,意为“否”),取决于是否可以通过 $k$ 次剪切恢复卷尺的初始状态。 如果答案是肯定的,接下来的 $k$ 行应每行包含两个整数 $l_i$ 和 $r_i$ ($1 \leq l_i \leq r_i \leq n$),表示需要翻转的连续片段的起始和结束下标。 如果存在多个正确答案,程序可以输出其中任意一个。

样例

输入格式 1

4 2
3 4 1 2

输出格式 1

TAK
1 3
2 4

说明

在 Bytie 玩过卷尺后,数字序列变为 $[3,\, 4,\, 1,\, 2]$。 在第一个样例中,我们可以通过两次操作恢复卷尺的初始状态:

  1. 剪切并翻转从第一个到第三个卷尺元素的片段,结果为:$[1,\, 4,\, 3,\, 2]$。
  2. 剪切并翻转从第二个到第四个卷尺元素的片段,结果为:$[1,\, 2,\, 3,\, 4]$。

输入格式 2

4 1
3 4 1 2

输出格式 2

NIE

说明

仅使用一次操作无法恢复卷尺的初始状态。

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.