-
Notifications
You must be signed in to change notification settings - Fork 0
/
squeeze.cpp
167 lines (124 loc) · 2.7 KB
/
squeeze.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//Squeezing
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define f(i,n) for(ll i=0;i<n;i++)
#define finm(n,m) for(ll i=0;i<n;i++) for(ll j=0;j<m;j++)
#define do(i,a,b) for(ll i=a;i<b;i++)
#define vi vector <int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
using namespace std;
#define peek(l,r) cout<<"--"<<l<<" "<<r<<"--"<<endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define deb(x) cout<<#x<<"->"<<x<<endl;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl;
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl;
const int N=500023;
//bool vis[N];
vector <int> adj[N];
int count=0;
const int maxn=500;
int grid[maxn][maxn];
int vis[maxn][maxn];
string s;
int val(int l,int h,int c){
int v=0;
for(int i=l;i<=h;i++){
v += !( (s[i] - 97) == c );
}
return v;
}
int pown(int a,int n){
if(n==0)return 1;
if(n==1)return a;
int t = pown(a,n/2);
return t*t*pown(a,n%2);
}
bool is_prime(int n){
int ok=1;
for(int i=2;i*i<=n;i++){
if(n%i==0){
ok=0;break;
}
}
return ok;
}
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
bool is_powertwo(int x){
return (x&&!(x&(x-1)));
}
int nc2(int n){
if(!n)return n;
return (n)*(n-1)/2;
}
//bool check(string s,int i){
// string t="";
// for(int j=0;j<7;j++){
//
// if(p[j]!=s[i+j] && s[i+j]!='?'){
// return false;
// }
// else{
//
//
//
// }
//
//
// }
// return t;
//}
void solve(){
int n,k;
cin>>n>>k;
vi a(n+1);
a.pb(0);
f(i,n)cin>>a[i+1];
vi p;
map<int,int> mp;
vi mn,mx;
for(int i=1;i<=n/2;i++){
p.pb(a[i]+a[n-i+1]);
mp[a[i]+a[n-i+1]]++;
mn.pb(min(a[i],a[n-i+1]));
mx.pb(max(a[i],a[n-i+1]));
}
int res=INT_MAX;
sort(all(mn));
sort(all(mx));
for(int x = 2;x<=2*k;x++){
int ans = 0;
int z0 = mn.end() - upper_bound(all(mn),x-1);
int z1 = lower_bound(all(mx), x-k) - mx.begin();
ans+=z0;
ans+=z1;
ans+=n/2;
ans-=mp[x];
res=min(res,ans);
}
d1(res);
}
int32_t main()
{
IOS;
int t=1;
cin>>t;
for(int i=1;i<=t;i++){
// cout<<"Case #"<<i<<": ";
solve();
}
}