fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. typedef long double ld;
  5. typedef vector<int> vi;
  6. typedef pair<int,int> pii;
  7. #define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  8. #define pb push_back
  9. #define MP make_pair
  10. #define F first
  11. #define S second
  12.  
  13. int main() {
  14. flash;
  15.  
  16.  
  17. int t; cin>>t;
  18. while(t--){
  19.  
  20. ll n,k; cin>>n>>k;
  21. ll i,j,x,y,z,N;
  22.  
  23. ll a[n]; for(i=0;i<n;i++){cin>>a[i];}
  24.  
  25. N = 2*k+1;
  26. ll b[N+1]; //elements to be replaced
  27. for(i=0;i<=N;i++){ b[i] = 0; }
  28.  
  29. for(i=0;i<n/2;i++){
  30.  
  31. x = min(a[i],a[n-i-1]);
  32. y = max(a[i],a[n-i-1]);
  33.  
  34. z = a[i] + a[n-i-1];
  35.  
  36. b[0] += 2;
  37. b[x+1] -= 1;
  38. b[z] -= 1;
  39. b[z+1] += 1;
  40. b[k+y+1] += 1;
  41. }
  42.  
  43. ll sum=0 , ans=n+1;
  44. for(i=0;i<=N;i++){
  45. sum += b[i];
  46. ans = min(ans,sum);
  47. }
  48. cout<<ans<<endl;
  49. }
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 4456KB
stdin
4
4 2
1 2 1 2
4 3
1 2 2 1
8 7
6 1 1 7 6 3 4 6
6 6
5 2 6 1 3 4
stdout
0
1
4
2