CF2200D.Portal

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a permutation∗^{\text{∗}} pp of length nn. There are also two portals located at positions xx and yy (x<yx \lt y).

A portal at position ii is initially located between the ii-th and (i+1)(i+1)-th elements of the array. Specifically, if i=0i=0, then the portal is located before the first element of the array, and if i=ni=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:

  1. Remove the element to the immediate left of one portal and insert it to the immediate right of the other portal.
  2. Remove the element to the immediate right of one portal and insert it to the immediate left of the other portal.

Let O\mathbf{\color{red}{\mathcal{O}}} denote a portal. For example, if pp is [3,O,2,4,O,1][3,\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}},1]:

  • Using operation 11 on the left and right portals respectively results in the arrays [O,2,4,O,3,1][\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}},3,1] and [3,O,4,2,O,1][3,\mathbf{\color{red}{\mathcal{O}}},4,2,\mathbf{\color{red}{\mathcal{O}}},1].
  • Using operation 22 on the left and right portals respectively results in the arrays [3,O,4,2,O,1][3,\mathbf{\color{red}{\mathcal{O}}},4,2,\mathbf{\color{red}{\mathcal{O}}},1] and [3,1,O,2,4,O][3,1,\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}}].

Find the lexicographically†^{\text{†}} smallest permutation you can obtain using these operations. Note that portals do not affect the lexicographical comparison of permutations.

∗^{\text{∗}}A permutation of length nn is an array of length nn containing each integer from 11 to nn exactly once.

†^{\text{†}}A permutation aa is lexicographically smaller than permutation bb if there exists an index ii such that aj=bja_j = b_j for all indices 1≤j<i1 \leq j \lt i and ai<bia_i \lt b_i.

给你一个长度为 nn 的排列∗^{\text{∗}} pp。此外,还有两个传送门分别位于位置 xx 和 yy(其中 x<yx \lt y)。

位于位置 ii 的传送门初始时处于数组第 ii 个元素与第 (i+1)(i+1) 个元素之间。具体而言:若 i=0i = 0,则传送门位于数组第一个元素之前;若 i=ni = n,则传送门位于数组最后一个元素之后。

你可以任意次执行以下两种操作之一:

  1. 将某一个传送门正左侧的元素移除,并将其插入到另一个传送门的正右侧;
  2. 将某一个传送门正右侧的元素移除,并将其插入到另一个传送门的正左侧。

用 O\mathbf{\color{red}{\mathcal{O}}} 表示一个传送门。例如,若 pp 为 [3,O,2,4,O,1][3,\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}},1]:

  • 对左、右传送门分别执行操作 11,得到的数组分别为 [O,2,4,O,3,1][\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}},3,1] 和 [3,O,4,2,O,1][3,\mathbf{\color{red}{\mathcal{O}}},4,2,\mathbf{\color{red}{\mathcal{O}}},1];
  • 对左、右传送门分别执行操作 22,得到的数组分别为 [3,O,4,2,O,1][3,\mathbf{\color{red}{\mathcal{O}}},4,2,\mathbf{\color{red}{\mathcal{O}}},1] 和 [3,1,O,2,4,O][3,1,\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}}]。

求使用这些操作所能得到的字典序†^{\text{†}}最小的排列。注意:传送门不参与排列的字典序比较。

∗^{\text{∗}} 长度为 nn 的排列是指一个长度为 nn 的数组,其中恰好包含 11 到 nn 的每个整数各一次。

†^{\text{†}} 排列 aa 字典序小于排列 bb,当且仅当存在某个下标 ii,使得对所有满足 1≤j<i1 \leq j \lt i 的下标 jj 均有 aj=bja_j = b_j,且 ai<bia_i \lt b_i。

输入格式

The first line contains an integer tt (1≤t≤2⋅1041 \leq t \leq 2\cdot 10^4) — the number of test cases.

For each test case, the first line contains three integers nn, xx, and yy (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 0≤x<y≤n0 \leq x \lt y \leq n).

The second line of each test case contains nn integers p1,p2,…,pnp_1, p_2, \dots, p_n — a permutation of length nn.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤2⋅1041 \leq t \leq 2\cdot 10^4)—— 测试用例的数量。

对于每个测试用例,第一行包含三个整数 nn、xx 和 yy(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,0≤x<y≤n0 \leq x \lt y \leq n)。

每个测试用例的第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \dots, p_n —— 一个长度为 nn 的排列。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a line with nn integers — the lexicographically smallest permutation you can obtain.

对于每个测试用例,输出一行包含 nn 个整数——你能得到的字典序最小的排列。

输入输出样例

  • 输入#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\mathbf{\color{red}{\mathcal{O}}} denote a portal.

In the first test case, the array is [O,3,1,4,2,O][\mathbf{\color{red}{\mathcal{O}}},3,1,4,2,\mathbf{\color{red}{\mathcal{O}}}]. Using operation 22 on the left portal results in [O,1,4,2,3,O][\mathbf{\color{red}{\mathcal{O}}},1,4,2,3,\mathbf{\color{red}{\mathcal{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][3,\mathbf{\color{red}{\mathcal{O}}},2,\mathbf{\color{red}{\mathcal{O}}},1]. Using operation 11 on the left portal results in [O,2,O,3,1][\mathbf{\color{red}{\mathcal{O}}},2,\mathbf{\color{red}{\mathcal{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\mathbf{\color{red}{\mathcal{O}}} 表示一个传送门。

在第一个测试用例中,数组为 [O,3,1,4,2,O][\mathbf{\color{red}{\mathcal{O}}},3,1,4,2,\mathbf{\color{red}{\mathcal{O}}}]。对左侧的传送门执行操作 22,得到 [O,1,4,2,3,O][\mathbf{\color{red}{\mathcal{O}}},1,4,2,3,\mathbf{\color{red}{\mathcal{O}}}],这是所能获得的字典序最小的排列。

上述所描述的操作。

在第二个测试用例中,数组为 [3,O,2,O,1][3,\mathbf{\color{red}{\mathcal{O}}},2,\mathbf{\color{red}{\mathcal{O}}},1]。对左侧的传送门执行操作 11,得到 [O,2,O,3,1][\mathbf{\color{red}{\mathcal{O}}},2,\mathbf{\color{red}{\mathcal{O}}},3,1],这是所能获得的字典序最小的排列。

在第四个测试用例中,最优策略是不执行任何操作。

输入解题思路,AI测评打分。不知道怎么写?

首页