CF2162E.Beautiful Palindromes

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

We call an array [b1,b2,…,bm][b_1, b_2, \dots, b_m] of length mm palindromic if the following condition holds:

  • bi=bm−i+1b_i = b_{m-i+1} for all 1≤i≤m1 \le i \le m

In other words, an array is palindromic if it reads the same forward and backward.

You are given an array [a1,a2,…,an][a_1, a_2, \dots , a_n] of nn integers where 1≤ai≤n1 \le a_i \le n and an integer kk.

You are required to perform the following operation exactly kk times:

  • choose an integer xx such that 1≤x≤n1 \le x \le n,
  • append xx to the end of the array aa.

Your goal is to perform these kk operations in such a way that the number of palindromic subarrays∗^{\text{∗}} in the resulting array is minimized.

Output the kk integers you chose for each operation, in the order they were appended.

∗^{\text{∗}}An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

我们称一个长度为 mm 的数组 [b1,b2,…,bm][b_1, b_2, \dots, b_m] 是回文的,如果满足以下条件:

  • 对所有 1≤i≤m1 \le i \le m,有 bi=bm−i+1b_i = b_{m-i+1}。

换言之,一个数组是回文的,当且仅当它正读与反读完全相同。

给定一个由 nn 个整数组成的数组 [a1,a2,…,an][a_1, a_2, \dots , a_n],其中 1≤ai≤n1 \le a_i \le n,以及一个整数 kk。

你需要恰好执行以下操作 kk 次:

  • 选择一个整数 xx,满足 1≤x≤n1 \le x \le n,
  • 将 xx 追加到数组 aa 的末尾。

你的目标是以某种方式执行这 kk 次操作,使得最终数组中回文子数组∗^{\text{∗}} 的数量最小。

请按追加顺序输出你每次操作所选的 kk 个整数。

∗^{\text{∗}} 若数组 bb 可通过从数组 aa 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 bb 是 aa 的一个子数组。特别地,一个数组是其自身的子数组。

输入格式

The first line of input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn and kk (3≤n≤2⋅105,1≤k≤n3 \le n \le 2\cdot10^5, 1 \le k \le n) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots , a_n (1≤ai≤n1 \le a_i \le n) — the elements of the array aa.

It is guaranteed that the sum of nn over all the test cases does not exceed 2⋅1052\cdot10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 kk(3≤n≤2⋅105, 1≤k≤n3 \le n \le 2\cdot10^5,\ 1 \le k \le n),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots , a_n(1≤ai≤n1 \le a_i \le n),表示数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot10^5。

输出格式

For each test case, print the kk integers chosen for the append operations, in the order they were appended, such that the total number of palindromic subarrays in the resulting array is minimized.

If there are multiple answers, you may output any one of them.

对于每个测试用例,请按追加操作执行的顺序输出所选择的 kk 个整数,使得最终数组中回文子数组的总数最小。

若存在多个满足条件的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    4 1
    1 3 3 4
    4 2
    2 2 2 2
    5 1
    4 1 5 2 2
    6 3
    1 2 3 4 5 6
    5 3
    3 2 5 2 3

    输出#1

    2 
    1 3 
    3 
    3 4 1
    4 1 5

说明/提示

For the first test case, if we append 22 to the end of the array, aa becomes [1,3,3,4,2][1, 3, 3, 4, 2]. Now aa has only 66 palindromic subarrays — [1][1], [3][3], [3][3], [4][4], [2][2], [3,3][3, 3].

对于第一个测试用例,如果我们在数组末尾追加 22,则 aa 变为 [1,3,3,4,2][1, 3, 3, 4, 2]。此时 aa 仅有 66 个回文子数组——[1][1]、[3][3]、[3][3]、[4][4]、[2][2]、[3,3][3, 3]。

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

首页