https://codeforces.ml/problemset/problem/1343/D

差分:

对于每一对max+min=sum,当sum等于以下区间的值时需要改变的次数;

[2,min]+=2;

[max+k+1,2*k]+=2;

[min+1,max+k]+=1;  [max+min,max+min]-=1;

#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e6+5;
typedef long long ll;
const int mod=1e9+7;
typedef  unsigned long long ull;
//typedef __int128 LL;
const double eps=10e-8;
const double pi=acos(-1.0);
#define between(x,a,b)(a<=x && x<=b)
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3f;
typedef pair<ll,ll> pII;
typedef pair<int,int> pii;
typedef pair<int,ll> piI;
int a[MAXN];
int f[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("1.in", "r", stdin);
    freopen("debug.out", "w", stdout);
#endif
    int t;
    scanf("%d",&t);
    while(t--)
    {
        
        int n,k;
        scanf("%d%d",&n,&k);
        for(int i=1;i<=2*k;i++)f[i]=0;
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        for(int i=1;i<=n/2;i++)
        {
            int maxn=max(a[i],a[n-i+1]);
            int minn=min(a[i],a[n-i+1]);
            f[2]+=2;f[minn+1]-=2;
            f[maxn+k+1]+=2;f[2*k+1]-=2;
            f[minn+1]+=1;f[maxn+k+1]-=1;
            f[maxn+minn]--;f[maxn+minn+1]++;
        }
        int ans=inf;
        for(int i=2;i<=2*k;i++)
        {
            f[i]=f[i-1]+f[i];
            ans=min(f[i],ans);
        }
        printf("%d\n",ans);

    }
    return 0;
}
View Code

 

posted on 2020-12-14 22:44  MZRONG  阅读(94)  评论(0编辑  收藏  举报