/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
1 から N までの番号が書かれた(表裏の区別できる)N 枚のカードがあり、 最初、上から 1,2,\ldots,N の順ですべて表向きで積まれています。
高橋君はこの山に Q 回の操作を行います。i 回目(1\leq i\leq Q)の操作では以下の操作を行います。
上から K_i 枚のカードをひとまとめにして裏返し、元の位置に戻す。
これにより、上から K_i 枚のカードの順序が上下逆になり、それぞれのカードの表裏も反転する。
すべての操作を終えた後のカードの順序と表裏を求めてください。
具体的には、i=1,2,\ldots,N について、上から i 枚目に置かれているカードに書かれている番号が X_i のとき、そのカードが表向きで積まれている時 X_i を、裏向きなら -X_i を出力してください。
制約
- 1 \leq N,Q \leq 100
- 1 \leq K_i \leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N Q K_1 K_2 \cdots K_Q
出力
N 行出力せよ。i 行目(1\leq i\leq N)には、Q 回の操作の後で上から i 枚目に置かれているカードに書かれている番号が X_i のとき、そのカードが表向きで積まれている時 X_i を、裏向きなら -X_i を出力せよ。
入力例 1
5 2 3 5
出力例 1
-5 -4 1 2 3
以下では番号 i が書かれたカードが表向きで置かれている状態を i 表、裏向きで置かれている状態を i 裏、で表します。
最初、積まれているカードの状態は上から順に(1 表、2 表、3 表、4 表、5 表)です。
1 回目の操作で上から 3 枚のカードをひとまとめにして裏返すと、状態は上から順に(3 裏、2 裏、1 裏、4 表、5 表)となります。
次に、2 回目の操作で上から 5 枚のカードをすべてひとまとめにして裏返すと、状態は上から順に(5 裏、4 裏、1 表、2 表、3 表)となります。
よって、-5,-4,1,2,3 を各行にこの順に出力します。
入力例 2
1 1 1
出力例 2
-1
1 回の操作の後で、1 の書かれたカードが裏向きで置かれています。 よって、-1 を出力します。
Score : 200 points
Problem Statement
There are N cards numbered 1 to N, each with a distinguishable front and back. Initially, they are stacked in the order 1,2,\ldots,N from the top, all face up.
Takahashi performs Q operations on this stack. The i-th operation (1\leq i\leq Q) is as follows.
Flip the top K_i cards over together as a single block and put them back in place.
This reverses the top-to-bottom order of the top K_i cards and also turns each of those cards over.
Find the order and orientation of the cards after all operations.
Specifically, for each i=1,2,\ldots,N, let X_i be the number written on the i-th card from the top; print X_i if that card is face up, and -X_i if it is face down.
Constraints
- 1 \leq N,Q \leq 100
- 1 \leq K_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q K_1 K_2 \cdots K_Q
Output
Print N lines. For the i-th line (1\leq i\leq N), let X_i be the number written on the i-th card from the top after the Q operations; print X_i if that card is face up, and -X_i if it is face down.
Sample Input 1
5 2 3 5
Sample Output 1
-5 -4 1 2 3
Below, we write "i up" for the card numbered i placed face up, and "i down" for the card numbered i placed face down.
Initially, the states of the stacked cards, from the top, are (1 up, 2 up, 3 up, 4 up, 5 up).
The 1-st operation flips the top 3 cards together, so the states become (3 down, 2 down, 1 down, 4 up, 5 up) from the top.
Next, the 2-nd operation flips all of the top 5 cards together, so the states become (5 down, 4 down, 1 up, 2 up, 3 up) from the top.
Thus, print -5,-4,1,2,3 in this order, one per line.
Sample Input 2
1 1 1
Sample Output 2
-1
After the single operation, the card numbered 1 is face down. Thus, print -1.