CF1256B Minimize the Permutation

题目描述

给你一个长度为 $n$ 排列,你需要经过至多 $n-1$ 次的交换,使得排列的字典序尽量小。 这里要注意:交换仅能交换相邻的两数,且每个位置只能交换一次。 位置的定义如下: 交换 $a_1,a_2$ 两数称为在位置 $1$ 上的交换,交换 $a_2,a_3$ 两数称为在位置 $2$ 上的交换,......,交换 $a_{n-1},a_{n}$ 两数称为在位置 $n-1$ 上的交换。

输入格式

本题有多组数据 第一行输入一个数 $q$ ,表示有 $q$ 组数据 对于每组数据: 第一行输入一个数 $n$,表示有 $n$ 个数。 下面一行输入 $n$ 个数,代表给出的排列

输出格式

对于每个数据,输出交换后,字典序最小的结果。

说明/提示

Recall that the permutation $ p $ of length $ n $ is lexicographically less than the permutation $ q $ of length $ n $ if there is such index $ i \le n $ that for all $ j $ from $ 1 $ to $ i - 1 $ the condition $ p_j = q_j $ is satisfied, and $ p_i < q_i $ . For example: - $ p = [1, 3, 5, 2, 4] $ is less than $ q = [1, 3, 5, 4, 2] $ (such $ i=4 $ exists, that $ p_i < q_i $ and for each $ j < i $ holds $ p_j = q_j $ ), - $ p = [1, 2] $ is less than $ q = [2, 1] $ (such $ i=1 $ exists, that $ p_i < q_i $ and for each $ j < i $ holds $ p_j = q_j $ ).