完整代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int s[N<<1];
int main() {
int T; cin>>T;
while(T--) {
memset(s, 0, sizeof s);
int n, k; cin>>n>>k;
int res = 1e8;
for(int i = 1; i <= n; i++)
cin>>a[i];
for(int i = 1; i <= n/2; i++) {
int &p = a[i], &q = a[n-i+1];
if(p > q) swap(p, q);
s[1] += 2, s[1+p]--, s[q+k+1]++;
}
for(int i = 1; i <= 2*k+1; i++)
s[i] += s[i-1];
for(int i = 1; i <= n/2; i++) s[a[i] + a[n-i+1]]--;
for(int i = 1; i <= 2*k; i++)
res = min(res, s[i]);
cout<<res<<endl;
}
}