CF2200D.Portal
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation∗ p of length n. There are also two portals located at positions x and y (x<y).
A portal at position i is initially located between the i-th and (i+1)-th elements of the array. Specifically, if i=0, then the portal is located before the first element of the array, and if i=n, then the portal is located after the last element.
You may perform either of the following two operations as many times as you like:
- Remove the element to the immediate left of one portal and insert it to the immediate right of the other portal.
- Remove the element to the immediate right of one portal and insert it to the immediate left of the other portal.
Let O denote a portal. For example, if p is [3,O,2,4,O,1]:
- Using operation 1 on the left and right portals respectively results in the arrays [O,2,4,O,3,1] and [3,O,4,2,O,1].
- Using operation 2 on the left and right portals respectively results in the arrays [3,O,4,2,O,1] and [3,1,O,2,4,O].
Find the lexicographically† smallest permutation you can obtain using these operations. Note that portals do not affect the lexicographical comparison of permutations.
∗A permutation of length n is an array of length n containing each integer from 1 to n exactly once.
†A permutation a is lexicographically smaller than permutation b if there exists an index i such that aj=bj for all indices 1≤j<i and ai<bi.
给你一个长度为 n 的排列∗ p。此外,还有两个传送门分别位于位置 x 和 y(其中 x<y)。
位于位置 i 的传送门初始时处于数组第 i 个元素与第 (i+1) 个元素之间。具体而言:若 i=0,则传送门位于数组第一个元素之前;若 i=n,则传送门位于数组最后一个元素之后。
你可以任意次执行以下两种操作之一:
- 将某一个传送门正左侧的元素移除,并将其插入到另一个传送门的正右侧;
- 将某一个传送门正右侧的元素移除,并将其插入到另一个传送门的正左侧。
用 O 表示一个传送门。例如,若 p 为 [3,O,2,4,O,1]:
- 对左、右传送门分别执行操作 1,得到的数组分别为 [O,2,4,O,3,1] 和 [3,O,4,2,O,1];
- 对左、右传送门分别执行操作 2,得到的数组分别为 [3,O,4,2,O,1] 和 [3,1,O,2,4,O]。
求使用这些操作所能得到的字典序†最小的排列。注意:传送门不参与排列的字典序比较。
∗ 长度为 n 的排列是指一个长度为 n 的数组,其中恰好包含 1 到 n 的每个整数各一次。
† 排列 a 字典序小于排列 b,当且仅当存在某个下标 i,使得对所有满足 1≤j<i 的下标 j 均有 aj=bj,且 ai<bi。
输入格式
The first line contains an integer t (1≤t≤2⋅104) — the number of test cases.
For each test case, the first line contains three integers n, x, and y (1≤n≤2⋅105, 0≤x<y≤n).
The second line of each test case contains n integers p1,p2,…,pn — a permutation of length n.
The sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤2⋅104)—— 测试用例的数量。
对于每个测试用例,第一行包含三个整数 n、x 和 y(1≤n≤2⋅105,0≤x<y≤n)。
每个测试用例的第二行包含 n 个整数 p1,p2,…,pn —— 一个长度为 n 的排列。
所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, output a line with n integers — the lexicographically smallest permutation you can obtain.
对于每个测试用例,输出一行包含 n 个整数——你能得到的字典序最小的排列。
输入输出样例
输入#1
4 4 0 4 3 1 4 2 3 1 2 3 2 1 5 1 3 1 3 5 2 4 2 0 1 1 2
输出#1
1 4 2 3 2 3 1 1 2 3 5 4 1 2
说明/提示
Let O denote a portal.
In the first test case, the array is [O,3,1,4,2,O]. Using operation 2 on the left portal results in [O,1,4,2,3,O], which is the lexicographically smallest possible permutation that can be obtained.
The operation described above.
In the second test case, the array is [3,O,2,O,1]. Using operation 1 on the left portal results in [O,2,O,3,1], which is the lexicographically smallest possible permutation that can be obtained.
In the fourth test case, it is optimal not to do any operations.
设 O 表示一个传送门。
在第一个测试用例中,数组为 [O,3,1,4,2,O]。对左侧的传送门执行操作 2,得到 [O,1,4,2,3,O],这是所能获得的字典序最小的排列。
上述所描述的操作。
在第二个测试用例中,数组为 [3,O,2,O,1]。对左侧的传送门执行操作 1,得到 [O,2,O,3,1],这是所能获得的字典序最小的排列。
在第四个测试用例中,最优策略是不执行任何操作。
输入解题思路,AI测评打分。不知道怎么写?