CF1343D.Constant Palindrome Sum

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn integers (it is guaranteed that nn is even, i.e. divisible by 22). All aia_i does not exceed some integer kk.

Your task is to replace the minimum number of elements (replacement is the following operation: choose some index ii from 11 to nn and replace aia_i with some integer in range [1;k][1; k]) to satisfy the following conditions:

  • after all replacements, all aia_i are positive integers not greater than kk;
  • for all ii from 11 to n2\frac{n}{2} the following equation is true: ai+an−i+1=xa_i + a_{n - i + 1} = x, where xx should be the same for all n2\frac{n}{2} pairs of elements.

You have to answer tt independent test cases.

给你一个包含 nn 个整数的数组 aa(保证 nn 为偶数,即可被 22 整除)。所有 aia_i 均不超过某个整数 kk。

你的任务是通过最少次数的元素替换操作(替换操作定义为:选择一个下标 ii(1≤i≤n1 \le i \le n),并将 aia_i 替换为区间 [1,k][1, k] 中的某个整数),使得替换后的数组满足以下条件:

  • 替换完成后,所有 aia_i 均为不超过 kk 的正整数;
  • 对所有 i=1,2,…,n2i = 1, 2, \dots, \frac{n}{2},均有 ai+an−i+1=xa_i + a_{n - i + 1} = x,其中 xx 对全部 n2\frac{n}{2} 对元素均取相同值。

你需要处理 tt 个相互独立的测试用例。

输入格式

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

The first line of the test case contains two integers nn and kk (2≤n≤2⋅105,1≤k≤2⋅1052 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5) — the length of aa and the maximum possible value of some aia_i correspondingly. It is guratanteed that nn is even (i.e. divisible by 22). The second line of the test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤k1 \le a_i \le k), where aia_i is the ii-th element of aa.

It is guaranteed that the sum of nn (as well as the sum of kk) over all test cases does not exceed 2⋅1052 \cdot 10^5 (∑n≤2⋅105\sum n \le 2 \cdot 10^5, ∑k≤2⋅105\sum k \le 2 \cdot 10^5).

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

每个测试用例的第一行包含两个整数 nn 和 kk(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤k≤2⋅1051 \le k \le 2 \cdot 10^5),分别表示数组 aa 的长度以及数组中某个元素 aia_i 可能的最大值。保证 nn 为偶数(即能被 22 整除)。每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤k1 \le a_i \le k),其中 aia_i 是数组 aa 的第 ii 个元素。

保证所有测试用例的 nn 之和(以及所有测试用例的 kk 之和)均不超过 2⋅1052 \cdot 10^5(即 ∑n≤2⋅105\sum n \le 2 \cdot 10^5,∑k≤2⋅105\sum k \le 2 \cdot 10^5)。

输出格式

For each test case, print the answer — the minimum number of elements you have to replace in aa to satisfy the conditions from the problem statement.

对于每个测试用例,输出答案——即为满足题目所述条件,你需要替换数组 aa 中的最少元素个数。

输入输出样例

  • 输入#1

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

    输出#1

    0
    1
    4
    2

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

首页