#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
const int N=2e5+5;
int n,m,T,k;
int arr[N],ind[N];
void q(int a, int b) {
swap(arr[a],arr[b]); swap(arr[n-a+1],arr[n-b+1]);
}
void test_case() {
cin>>n;
vector<pii> op;
for (int i=1; i<=n; i++) {
cin>>arr[i];
}
vector<int> v;
int bestans=0;
for (int i=1; i<=n; i++) {
if (arr[i]+arr[n-i+1]!=n+1) {
cout<<-1<<endl;
return;
}
if (i<=n/2) {
if (arr[i]>arr[n-i+1]) v.pb(i);
if (arr[i]!=i && arr[n-i+1]!=i) bestans++;
}
}
int sz=v.size();
if (sz%2) {
cout<<-1<<endl;
return;
}
for (int i=0; i<sz; i+=2) {
q(v[i],n-v[i+1]+1);
op.pb({v[i],n-v[i+1]+1});
}
for (int i=1; i<=n; i++) {
ind[arr[i]]=i;
}
for (int i=1; i<=n/2; i++) {
if (arr[i]==i) continue;
int idx=ind[i],val=arr[i];
op.pb({i,idx});
swap(arr[i],arr[idx]);
swap(ind[i],ind[val]);
}
cout<<bestans<<" "<<op.size()<<endl;
for (auto AA:op) {
cout<<AA.f<<" "<<AA.s<<endl;
}
}
main () {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
T=1; cin>>T;
while (T--) test_case();
}
Compilation message (stderr)
cat.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
cat.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main () {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |