CF1343D.Constant Palindrome Sum
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All ai does not exceed some integer k.
Your task is to replace the minimum number of elements (replacement is the following operation: choose some index i from 1 to n and replace ai with some integer in range [1;k]) to satisfy the following conditions:
- after all replacements, all ai are positive integers not greater than k;
- for all i from 1 to 2n the following equation is true: ai+an−i+1=x, where x should be the same for all 2n pairs of elements.
You have to answer t independent test cases.
给你一个包含 n 个整数的数组 a(保证 n 为偶数,即可被 2 整除)。所有 ai 均不超过某个整数 k。
你的任务是通过最少次数的元素替换操作(替换操作定义为:选择一个下标 i(1≤i≤n),并将 ai 替换为区间 [1,k] 中的某个整数),使得替换后的数组满足以下条件:
- 替换完成后,所有 ai 均为不超过 k 的正整数;
- 对所有 i=1,2,…,2n,均有 ai+an−i+1=x,其中 x 对全部 2n 对元素均取相同值。
你需要处理 t 个相互独立的测试用例。
输入格式
The first line of the input contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.
The first line of the test case contains two integers n and k (2≤n≤2⋅105,1≤k≤2⋅105) — the length of a and the maximum possible value of some ai correspondingly. It is guratanteed that n is even (i.e. divisible by 2). The second line of the test case contains n integers a1,a2,…,an (1≤ai≤k), where ai is the i-th element of a.
It is guaranteed that the sum of n (as well as the sum of k) over all test cases does not exceed 2⋅105 (∑n≤2⋅105, ∑k≤2⋅105).
输入的第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。接下来是 t 个测试用例。
每个测试用例的第一行包含两个整数 n 和 k(2≤n≤2⋅105,1≤k≤2⋅105),分别表示数组 a 的长度以及数组中某个元素 ai 可能的最大值。保证 n 为偶数(即能被 2 整除)。每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤k),其中 ai 是数组 a 的第 i 个元素。
保证所有测试用例的 n 之和(以及所有测试用例的 k 之和)均不超过 2⋅105(即 ∑n≤2⋅105,∑k≤2⋅105)。
输出格式
For each test case, print the answer — the minimum number of elements you have to replace in a to satisfy the conditions from the problem statement.
对于每个测试用例,输出答案——即为满足题目所述条件,你需要替换数组 a 中的最少元素个数。
输入输出样例
输入#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测评打分。不知道怎么写?