Professional Documents
Culture Documents
{
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
vi a(n+5);
vi pos(n+5);
FOR(i,0,n)
{
cin>>a[i];
a[i]--;
pos[a[i]] = i;
}
FOR(i,0,n-2)
{
if(pos[i]==i) continue;
if((pos[i]-i)%2==0)
{
RFOR(j,pos[i],i)
{
pos[a[j]]++;
a[j+1] = a[j];
}
}
else
{
RFOR(j,pos[i],i+1)
{
pos[a[j]]++;
a[j+1] = a[j];
}
pos[a[i+2]] = i+1;
a[i+1] = a[i+2];
pos[a[i]] = i+2;
a[i+2] = a[i];
}
pos[i] = i;
a[i] = i;
}
if(a[n-2]<a[n-1]) cout<<"YES";
else cout<<"NO";
cout<<endl;
}
int main()
{
solve();
return 0;
}