fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n,k; cin>>n>>k;
  8. int arr[200005];
  9. for(int i=0; i<n; ++i){
  10. cin>>arr[i];
  11. }
  12. int preSum[400005];
  13. for(int i=0; i<200005; ++i){
  14. preSum[i] = 0;
  15. }
  16. for(int i=0;i<(n/2); ++i){
  17. int mn = min(arr[i], arr[n-i-1]);
  18. int mx = max(arr[i], arr[n-i-1]);
  19.  
  20. int valMin = mn+1;
  21. int valMax = min(k*2, mx+k);
  22.  
  23. preSum[valMin]+= 1;
  24. preSum[valMax]+= -1;
  25. }
  26. for(int i=1; i<400001; ++i){
  27. preSum[i] = preSum[i] + preSum[i-1];
  28. }
  29. for(int i=0; i<(n/2); ++i){
  30. preSum[arr[i]+arr[n-1-i]]+=1;
  31. }
  32. int mx = -1;
  33. for(int i=1; i<=2*k; ++i){
  34. mx = max(mx, preSum[i]);
  35. }
  36. cout<<(n-mx)<<"\n";
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
Standard output is empty