=暴搜每个x的改变次数,构造差分数组保存
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>
#include <cstring>
#include <string.h>
#include <queue>
#define ll int
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
inline ll read() {
ll k = 0, f = 1; char ch = getchar();
while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { k = k * 10 + ch - '0'; ch = getchar(); }return k * f;
}
ll a[200010];
ll x[400020];
int main()
{
ll t = read();
while (t--)
{
memset(x, 0, sizeof(x));
ll n = read(), k = read();
for (int i = 1; i <= n; i++)a[i] = read();
for (int i = 1; i <= n / 2; i++)
{
ll sum = a[i] + a[n - i + 1];
ll maxn = max(a[i], a[n - i + 1]);
ll minn = min(a[i], a[n - i + 1]);
x[2] += 2;
x[minn + 1]--;
x[maxn + k + 1]++;
x[2 * k + 1] -= 2;
x[sum]--;
x[sum + 1]++;
}
ll ans = inf;
ll now = 0;
for (int i = 2; i <= 2 * k; i++)
{
now += x[i];
ans = min(ans, now);
}
cout << ans << '\n';
}
}