#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#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() {
scanf("%d",&n);
vector<pii> op;
for (int i=1; i<=n; i++) {
scanf("%d",&arr[i]);
}
vector<int> v;
int bestans=0;
for (int i=1; i<=n; i++) {
if (arr[i]+arr[n-i+1]!=n+1) {
printf("-1\n");
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) {
printf("-1\n");
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]);
}
int SZ=op.size();
printf("%d %d\n",bestans,SZ);
for (auto AA:op) {
printf("%d %d\n",AA.f,AA.s);
}
}
main () {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
T=1; scanf("%d",&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 () {
| ^~~~
cat.cpp: In function 'void test_case()':
cat.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
cat.cpp:22:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d",&arr[i]);
| ~~~~~^~~~~~~~~~~~~~
cat.cpp: In function 'int main()':
cat.cpp:65:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | T=1; scanf("%d",&T);
| ~~~~~^~~~~~~~~
# | 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... |