CF1893B.Neutral Tonality

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn integers, as well as an array bb consisting of mm integers.

Let LIS(c)\text{LIS}(c) denote the length of the longest increasing subsequence of array cc. For example, LIS([2,1‾,1,3‾])\text{LIS}([2, \underline{1}, 1, \underline{3}]) = 22, LIS([1‾,7‾,9‾])\text{LIS}([\underline{1}, \underline{7}, \underline{9}]) = 33, LIS([3,1‾,2‾,4‾])\text{LIS}([3, \underline{1}, \underline{2}, \underline{4}]) = 33.

You need to insert the numbers b1,b2,…,bmb_1, b_2, \ldots, b_m into the array aa, at any positions, in any order. Let the resulting array be c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m}. You need to choose the positions for insertion in order to minimize LIS(c)\text{LIS}(c).

Formally, you need to find an array c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m} that simultaneously satisfies the following conditions:

  • The array a1,a2,…,ana_1, a_2, \ldots, a_n is a subsequence of the array c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m}.
  • The array c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m} consists of the numbers a1,a2,…,an,b1,b2,…,bma_1, a_2, \ldots, a_n, b_1, b_2, \ldots, b_m, possibly rearranged.
  • The value of LIS(c)\text{LIS}(c) is the minimum possible among all suitable arrays cc.

给你一个由 nn 个整数组成的数组 aa,以及一个由 mm 个整数组成的数组 bb。

记 LIS(c)\text{LIS}(c) 为数组 cc 的最长递增子序列 的长度。例如,LIS([2,1‾,1,3‾])=2\text{LIS}([2, \underline{1}, 1, \underline{3}]) = 2,LIS([1‾,7‾,9‾])=3\text{LIS}([\underline{1}, \underline{7}, \underline{9}]) = 3,LIS([3,1‾,2‾,4‾])=3\text{LIS}([3, \underline{1}, \underline{2}, \underline{4}]) = 3。

你需要将数字 b1,b2,…,bmb_1, b_2, \ldots, b_m 插入到数组 aa 中(可插在任意位置,顺序可任意)。设得到的数组为 c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m}。你需要选择插入位置,使得 LIS(c)\text{LIS}(c) 尽可能小。

形式化地说,你需要找到一个数组 c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m},使其同时满足以下条件:

  • 数组 a1,a2,…,ana_1, a_2, \ldots, a_n 是数组 c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m} 的一个子序列;
  • 数组 c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m} 由数字 a1,a2,…,an,b1,b2,…,bma_1, a_2, \ldots, a_n, b_1, b_2, \ldots, b_m 组成(顺序可重排);
  • 在所有满足上述条件的数组 cc 中,LIS(c)\text{LIS}(c) 的值最小。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤104)(1 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n,mn, m (1≤n≤2⋅105,1≤m≤2⋅105)(1 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5) — the length of array aa and the length of array bb.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤109)(1 \leq a_i \leq 10^9) — the elements of the array aa.

The third line of each test case contains mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m (1≤bi≤109)(1 \leq b_i \leq 10^9) — the elements of the array bb.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5, and the sum of mm over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt (1≤t≤104)(1 \leq t \leq 10^4) —— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 n,mn, m (1≤n≤2⋅105,1≤m≤2⋅105)(1 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5) —— 数组 aa 的长度和数组 bb 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤109)(1 \leq a_i \leq 10^9) —— 数组 aa 的元素。

每个测试用例的第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m (1≤bi≤109)(1 \leq b_i \leq 10^9) —— 数组 bb 的元素。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot 10^5,且所有测试用例中 mm 的总和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, output n+mn + m numbers — the elements of the final array c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m}, obtained after the insertion, such that the value of LIS(c)\text{LIS}(c) is minimized. If there are several answers, you can output any of them.

对于每个测试用例,输出 n+mn + m 个数——即插入操作后得到的最终数组 c1,c2,…,cn+mc_1, c_2, \ldots, c_{n+m} 的元素,使得 LIS(c)\text{LIS}(c) 的值最小。如果存在多个满足条件的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    7
    2 1
    6 4
    5
    5 5
    1 7 2 4 5
    5 4 1 2 7
    1 9
    7
    1 2 3 4 5 6 7 8 9
    3 2
    1 3 5
    2 4
    10 5
    1 9 2 3 8 1 4 7 2 9
    7 8 5 4 6
    2 1
    2 2
    1
    6 1
    1 1 1 1 1 1
    777

    输出#1

    6 5 4
    1 1 7 7 2 2 4 4 5 5
    9 8 7 7 6 5 4 3 2 1
    1 3 5 2 4
    1 9 2 3 8 8 1 4 4 7 7 2 9 6 5
    2 2 1
    777 1 1 1 1 1 1

说明/提示

In the first test case, LIS(a)=LIS([6,4])=1\text{LIS}(a) = \text{LIS}([6, 4]) = 1. We can insert the number 55 between 66 and 44, then LIS(c)=LIS([6,5,4])=1\text{LIS}(c) = \text{LIS}([6, 5, 4]) = 1.

In the second test case, LIS([1‾,7,2‾,4‾,5‾])\text{LIS}([\underline{1}, 7, \underline{2}, \underline{4}, \underline{5}]) = 44. After the insertion, c=[1,1,7,7,2,2,4,4,5,5]c = [1, 1, 7, 7, 2, 2, 4, 4, 5, 5]. It is easy to see that LIS(c)=4\text{LIS}(c) = 4. It can be shown that it is impossible to achieve LIS(c)\text{LIS}(c) less than 44.

在第一个测试用例中,LIS(a)=LIS([6,4])=1\text{LIS}(a) = \text{LIS}([6, 4]) = 1。我们可以在 66 和 44 之间插入数字 55,此时 LIS(c)=LIS([6,5,4])=1\text{LIS}(c) = \text{LIS}([6, 5, 4]) = 1。

在第二个测试用例中,LIS([1‾,7,2‾,4‾,5‾])=4\text{LIS}([\underline{1}, 7, \underline{2}, \underline{4}, \underline{5}]) = 4。插入后,c=[1,1,7,7,2,2,4,4,5,5]c = [1, 1, 7, 7, 2, 2, 4, 4, 5, 5]。显然有 LIS(c)=4\text{LIS}(c) = 4。可以证明,不可能使 LIS(c)\text{LIS}(c) 小于 44。

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

首页