CF686B.Little Robber Girl's Zoo

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.

The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.

Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.

小盗贼女孩喜欢在她的动物园里吓唬动物取乐。她决定将动物按非递减高度顺序排成一排。然而,动物们过于害怕,无法待在正确的位置上。

盗贼女孩起初很生气,但随后她决定自己来重新安排这些动物。她反复指定两个数 llrr,要求满足 rl+1r - l + 1 为偶数。接着,对位置在 llrr(含端点)之间的所有动物执行如下重排操作:位置 ll 上的动物与位置 l+1l+1 上的动物交换,位置 l+2l+2 上的动物与位置 l+3l+3 上的动物交换,……,最后位置 r1r-1 上的动物与位置 rr 上的动物交换。

请帮助盗贼女孩将动物按非递减高度顺序排列。你至多只能指定 2000020\,000 个区间段,否则盗贼女孩会感到厌烦,并再次开始吓唬动物。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo.

The second line contains n space-separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109), where a__i is the height of the animal occupying the i-th place.

第一行包含一个整数 nn1n1001 \leq n \leq 100)—— 表示强盗女孩动物园中动物的数量。

第二行包含 nn 个用空格分隔的整数 a1,a2,,ana_1, a_2, \dots, a_n1ai1091 \leq a_i \leq 10^9),其中 aia_i 表示占据第 ii 个位置的动物的高度。

输出格式

Print the sequence of operations that will rearrange the animals by non-decreasing height.

The output should contain several lines, i-th of the lines should contain two space-separated integers l__i and r__i (1 ≤ l__i < r__i ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed.

The number of operations should not exceed 20 000.

If the animals are arranged correctly from the start, you are allowed to output nothing.

输出将动物按非递减高度重新排列的操作序列。

输出应包含若干行,第 ii 行应包含两个以空格分隔的整数 lil_irir_i(满足 1li<rin1 \le l_i < r_i \le n),表示强盗女孩需指定的区间。这些区间应按操作执行的顺序给出。

操作总数不得超过 2000020\,000

如果动物初始时已按正确顺序排列,则允许不输出任何内容。

输入输出样例

  • 输入#1

    4
    2 1 4 3

    输出#1

    1 4
  • 输入#2

    7
    36 28 57 39 66 69 68

    输出#2

    1 4
    6 7
  • 输入#3

    5
    1 2 1 2 1

    输出#3

    2 5
    3 4
    1 4
    1 4

说明/提示

Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.

注意,你不需要最小化操作次数。任何执行不超过 20 000 次操作的解法都是允许的。

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

首页