查分数组资料
https://blog.csdn.net/qq_44786250/article/details/100056975
题解
https://www.cnblogs.com/stelayuri/p/12749332.html
我的代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f;
const int MAX = 2e5 + 10;
int a[MAX], del[2 * MAX];
int main() {
ll T;
scanf("%lld", &T);
while(T--) {
int n, k;
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
memset(del, 0, sizeof(del));
for(int i = 1; i <= n / 2; i++) {
int sum = a[i] + a[n - i + 1];
int minn = min(a[i], a[n - i + 1]);
int maxx = max(a[i], a[n - i + 1]);
del[2] += 2;
del[minn + 1]--;
del[maxx + k +1]++;
del[2 * k + 1]--;
del[sum]--;
del[sum + 1]++;
}
int ans = del[2];
for(int i = 3; i <= 2 * k; i++) {
del[i] += del[i - 1];
ans = min(ans, del[i]);
}
printf("%d\n", ans);
}
}