题目链接:https://codeforces.com/contest/1343/problem/D、
解题思路:差分来借,具体看这里
#include<bits/stdc++.h> using namespace std; const int maxn=4e5+10; const int inf=1e9+10; typedef long long ll; int a[maxn]; int del[maxn]; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k; memset(del,0,(2*k+10)*sizeof(int)); for(int i=1;i<=n;i++) { cin>>a[i]; } int minn,maxx; for(int i=1;i<=n/2;i++) { int sum=a[i]+a[n-i+1]; minn=min(a[i],a[n-i+1]); maxx=(sum-minn); del[2]+=2; del[minn+1]--; del[maxx+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]); } cout<<ans<<endl; } return 0; }