Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
(1,2,\cdots,2N) の順列 P=(P_1,P_2,\cdots,P_{2N}) が与えられます.
あなたは,以下の操作を 0 回以上 N 回以下行うことができます.
- 整数 x (1 \leq x \leq 2N-1) を選ぶ. P_x と P_{x+1} の値を入れ替える.
操作後の P が以下の条件を満たすような操作列を 1 つ示してください.
- 各 i=1,3,5,\cdots,2N-1 について,P_i<P_{i+1} である.
- 各 i=2,4,6,\cdots,2N-2 について,P_i>P_{i+1} である.
なお,条件を満たすような操作列が必ず存在することが証明できます.
制約
- 1 \leq N \leq 10^5
- (P_1,P_2,\cdots,P_{2N}) は (1,2,\cdots,{2N}) の順列
- 入力される値はすべて整数である
入力
入力は以下の形式で標準入力から与えられる.
N P_1 P_2 \cdots P_{2N}
出力
以下の形式で操作列を出力せよ.
K x_1 x_2 \cdots x_K
ここで,K は行う操作の回数 (0 \leq K \leq N) であり,x_i (1 \leq x_i \leq 2N-1) は i 回目の操作で選ぶ x の値である. 条件を満たす解が複数存在する場合,どれを出力しても正解とみなされる.
入力例 1
2 4 3 2 1
出力例 1
2 1 3
操作後は P=(3,4,1,2) となり,条件を満たします.
入力例 2
1 1 2
出力例 2
0
Score : 400 points
Problem Statement
You are given a permutation P=(P_1,P_2,\cdots,P_{2N}) of (1,2,\cdots,2N).
The following operation may be performed between 0 and N times (inclusive).
- Choose an integer x (1 \leq x \leq 2N-1). Swap the values of P_x and P_{x+1}.
Present a sequence of operations that make P satisfy the following conditions.
- P_i<P_{i+1} for each i=1,3,5,\cdots,2N-1;
- P_i>P_{i+1} for each i=2,4,6,\cdots,2N-2.
It can be proved that such a sequence of operations always exists.
Constraints
- 1 \leq N \leq 10^5
- (P_1,P_2,\cdots,P_{2N}) is a permutation of (1,2,\cdots,{2N}).
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N P_1 P_2 \cdots P_{2N}
Output
Print a desired sequence of operations in the following format:
K x_1 x_2 \cdots x_K
Here, K is the number of operations performed (0 \leq K \leq N), and x_i is the value of x chosen in the i-th operation (1 \leq x_i \leq 2N-1). If there are multiple solutions satisfying the condition, printing any of them will be accepted.
Sample Input 1
2 4 3 2 1
Sample Output 1
2 1 3
These operations make P=(3,4,1,2), which satisfies the conditions.
Sample Input 2
1 1 2
Sample Output 2
0