CF1343D.Constant Palindrome Sum

普及/提高-

通过率:0%

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+ani+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.

输入格式

The first line of the input contains one integer tt ( 1t1041 \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 ( 2n2105,1k21052 \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 ( 1aik1 \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 21052 \cdot 10^5 ( n2105\sum n \le 2 \cdot 10^5 , k2105\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.

输入输出样例

  • 输入#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
首页