CF339E.Three Swaps

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2, 3, ..., n.

Xenia trains horses before the performance. During the practice sessions, she consistently gives them commands. Each command is a pair of numbers l, r (1 ≤ l < r ≤ n). The command l, r means that the horses that are on the l-th, (l + 1)-th, (l + 2)-th, ..., r-th places from the left must be rearranged. The horses that initially stand on the l-th and r-th places will swap. The horses on the (l + 1)-th and (r - 1)-th places will swap. The horses on the (l + 2)-th and (r - 2)-th places will swap and so on. In other words, the horses that were on the segment [l, r] change their order to the reverse one.

For example, if Xenia commanded l = 2, r = 5, and the sequence of numbers of horses before the command looked as (2, 1, 3, 4, 5, 6), then after the command the sequence will be (2, 5, 4, 3, 1, 6).

We know that during the practice Xenia gave at most three commands of the described form. You have got the final sequence of numbers of horses by the end of the practice. Find what commands Xenia gave during the practice. Note that you do not need to minimize the number of commands in the solution, find any valid sequence of at most three commands.

养马人泽妮娅有 nn(n>1n > 1)匹马,排成一列。每匹马都有一个唯一的编号。初始时,从左起第 ii 匹马的编号为 ii。也就是说,马匹编号从左到右组成的序列为:1,2,3,…,n1, 2, 3, \dots, n。

泽妮娅在演出前对马匹进行训练。在训练过程中,她持续发出指令。每条指令由一对整数 l, rl,\,r(满足 1≤l<r≤n1 \le l < r \le n)构成。指令 l, rl,\,r 表示:将当前从左起第 ll、第 (l+1)(l+1)、第 (l+2)(l+2)、…、第 rr 个位置上的马重新排列。具体操作是:原来位于第 ll 位和第 rr 位的马互换位置;原来位于第 (l+1)(l+1) 位和第 (r−1)(r-1) 位的马互换位置;原来位于第 (l+2)(l+2) 位和第 (r−2)(r-2) 位的马互换位置;依此类推。换言之,原位于区间 [l, r][l,\,r] 内的所有马,其顺序被完全反转。

例如,若泽妮娅发出指令 l=2, r=5l = 2,\,r = 5,且指令前马匹编号序列为 (2,1,3,4,5,6)(2, 1, 3, 4, 5, 6),则指令执行后序列变为 (2,5,4,3,1,6)(2, 5, 4, 3, 1, 6)。

已知在整个训练过程中,泽妮娅至多发出了三条上述形式的指令。你得到了训练结束后的马匹编号最终序列。请找出泽妮娅在训练中所发出的指令序列。注意:你无需使指令条数最少,只需找出任意一个长度不超过三条的合法指令序列即可。

输入格式

The first line contains an integer n (2 ≤ n ≤ 1000) — the number of horses in the row. The second line contains n distinct integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ n), where a__i is the number of the i-th left horse in the row after the practice.

第一行包含一个整数 nn(2≤n≤10002 \leq n \leq 1000)—— 表示马匹排成一列的数量。
第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \leq a_i \leq n),其中 aia_i 表示训练结束后从左往右数第 ii 匹马的编号。

输出格式

The first line should contain integer k (0 ≤ k ≤ 3) — the number of commads Xenia gave during the practice. In each of the next k lines print two integers. In the i-th line print numbers l__i, r__i (1 ≤ l__i < r__i ≤ n) — Xenia's i-th command during the practice.

It is guaranteed that a solution exists. If there are several solutions, you are allowed to print any of them.

第一行应包含一个整数 kk(0≤k≤30 \leq k \leq 3)—— Xenia 在训练过程中发出的指令数量。接下来的 kk 行中,每行输出两个整数:第 ii 行输出数字 li, ril_i,\, r_i(1≤li<ri≤n1 \leq l_i < r_i \leq n)—— 表示 Xenia 在训练过程中的第 ii 条指令。

保证存在解。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    1 4 3 2 5

    输出#1

    1
    2 4
  • 输入#2

    6
    2 1 4 3 6 5

    输出#2

    3
    1 2
    3 4
    5 6

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

首页