Hint : however you construct the permutation , both \sum\limits_{i=1}^{n} p_i and MEX(p_1 , p_2 , ... , p_n) are fixed.
Hint : for each where i < n, you can always get (p_1 , p_2 , ... , p_i) equals by setting p_n = 1.
Solution: Since all integers are divisible by , we have only to check the condition for i=n , where equals \frac{n \cdot (n+1)}{2} , and equals n+1, \frac{\text{sum}}{\text{mex}} = \frac{n}{2} , so when is odd , the condition is not fulfilled, so the answer is NO; otherwise, the answer is YES. Any permutation where p_n = 1 is a valid construction.
Time complexity :
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define F first
#define S second
using namespace std;
const int N = 2e5 + 1;
const int M = 1e9 + 7;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tc = 1;
cin>>tc;
while(tc--)
{
int n;
cin>>n;
if(n % 2 == 1)
{
cout<<"NO"<<endl;
continue;
}
cout<<"YES"<<endl;
int ans[n+1];
for(int i=1;i<=n;i++)
ans[i] = i;
swap(ans[1] , ans[n]);
for(int i=1;i<=n;i++)
cout<<ans[i]<<' ';
cout<<endl;
}
}