P27593 [洛谷] [NICA #1] Swap
普及+
题目描述

Problem Description

Given a permutation \(a\) of length \(n\). A permutation means that the numbers \(1, 2, 3, \ldots, n\) appear exactly once in \(a\). Now there are \(m\) operations:

  • The 1st operation will swap the 1st largest (i.e., the largest) element with the 2nd largest element.
  • The 2nd operation will swap the 2nd largest element with the 3rd largest element.
  • The 3rd operation will swap the 3rd largest element with the 4th largest element.
  • ...
  • The \(n-1\)th operation will swap the \(n-1\)th largest element with the \(n\)th largest element.
  • The \(n\)th operation will swap the 1st largest element with the 2nd largest element.
  • The \(n+1\)th operation will swap the 2nd largest element with the 3rd largest element.
  • The \(n+2\)th operation will swap the 3rd largest element with the 4th largest element.
  • ...
  • The \(2n-2\)th operation will swap the \(n-1\)th largest element with the \(n\)th largest element.
  • ...

Formally, the \(i\)th operation will swap the \((i-1) \bmod (n-1) + 1\)th largest and the \((i-1) \bmod (n-1) + 2\)th largest numbers.

You need to determine the final state of the permutation.

Input Format

The first line contains two integers \(n\) and \(m\), as described in the problem statement.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\), describing the initial sequence \(a\).

Output Format

Output a single line containing \(n\) integers, representing the final sequence \(a\).

Sample Input and Output

Sample Input #1

5 10
1 5 3 4 2

Sample Output #1

4 2 3 1 5

Sample Input #2

10 1000000000
4 2 7 6 9 5 3 8 1 10

Sample Output #2

5 3 8 7 9 6 4 10 2 1

Sample Input #3

10 100000000000000000000000000000000000000000000000000
10 9 8 7 6 5 4 3 2 1

Sample Output #3

1 9 10 8 7 6 5 4 3 2

Notes

Sample 1 Explanation

  • Initially: \([1, 5, 3, 4, 2]\);
  • Swap the 1st and 2nd largest: \([1, 4, 3, 5, 2]\);
  • Swap the 2nd and 3rd largest: \([1, 3, 4, 5, 2]\);
  • Swap the 3rd and 4th largest: \([1, 2, 4, 5, 3]\);
  • Swap the 4th and 5th largest: \([2, 1, 4, 5, 3]\);
  • Swap the 1st and 2nd largest: \([2, 1, 5, 4, 3]\);
  • Swap the 2nd and 3rd largest: \([2, 1, 5, 3, 4]\);
  • Swap the 3rd and 4th largest: \([3, 1, 5, 2, 4]\);
  • Swap the 4th and 5th largest: \([3, 2, 5, 1, 4]\);
  • Swap the 1st and 2nd largest: \([3, 2, 4, 1, 5]\);
  • Swap the 2nd and 3rd largest: \([4, 2, 3, 1, 5]\).

Data Range and Constraints

For all data, it is guaranteed that \(1 \le n \le 10^5\) and \(0 \le m \le 10^{1000000}\).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 10 1 5 3 4 2
样例输出
4 2 3 1 5