#abc250c. C - Adjacent Swaps

C - Adjacent Swaps

Score : 300300 points

问题描述

设有 NN 个球从左到右排成一行。最初,从左边数第 ii 个球(1iN1 \leq i \leq N)上写着整数 ii

Takahashi 执行了 QQ 次操作。第 ii 次操作(1iQ1 \leq i \leq Q)如下:

  • 将写有整数 xix_i 的球与它右边的下一个球交换。如果原本写有整数 xix_i 的球是最右边的球,则与其左边的下一个球交换。

aia_i 表示执行完操作后,从左边数第 ii 个球(1iN1 \leq i \leq N)上所写的整数。求出 a1,,aNa_1,\ldots,a_N

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

NN balls are lined up in a row from left to right. Initially, the ii-th (1iN1 \leq i \leq N) ball from the left has an integer ii written on it.

Takahashi has performed QQ operations. The ii-th (1iQ1 \leq i \leq Q) operation was as follows.

  • Swap the ball with the integer xix_i written on it with the next ball to the right. If the ball with the integer xix_i written on it was originally the rightmost ball, swap it with the next ball to the left instead.

Let aia_i be the integer written on the ii-th (1iN1 \leq i \leq N) ball after the operations. Find a1,,aNa_1,\ldots,a_N.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1xiN1 \leq x_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ

x1x_1

\vdots

xQx_Q

Output

Print a1,,aNa_1,\ldots,a_N, with spaces in between.

Sample Input 1

5 5
1
2
3
4
5

Sample Output 1

1 2 3 5 4

The operations are performed as follows.

  • Swap the ball with 11 written on it with the next ball to the right. Now, the balls have integers 2,1,3,4,52,1,3,4,5 written on them, from left to right.
  • Swap the ball with 22 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,51,2,3,4,5 written on them, from left to right.
  • Swap the ball with 33 written on it with the next ball to the right. Now, the balls have integers 1,2,4,3,51,2,4,3,5 written on them, from left to right.
  • Swap the ball with 44 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,51,2,3,4,5 written on them, from left to right.
  • Swap the ball with 55 written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers 1,2,3,5,41,2,3,5,4 written on them, from left to right.

Sample Input 2

7 7
7
7
7
7
7
7
7

Sample Output 2

1 2 3 4 5 7 6

Sample Input 3

10 6
1
5
2
9
6
6

Sample Output 3

1 2 3 4 5 7 6 8 10 9

update @ 2024/3/10 10:41:03