This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,ull>pairull;
typedef pair<ll,pairll>pair3l;
typedef long double ld;
typedef pair<ld,ll>pairld;
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define N 100007
//#define MOD 998244353
#define INF 10000000000007
#define eps 0.0000000001
ll t,n,d[2*N];
queue<pairll>res,g;
vector<ll>v;
int main(){
cin>>t;
while(t--){
cin>>n;
while(res.size()>0)res.pop();
while(g.size()>0)g.pop();
v.clear();
for(int i=1;i<=n;i++){
cin>>d[i];
}
ll fl=0;
for(int i=1;i<=n/2;i++){
if(d[i]+d[n-i+1]!=n+1)fl=-1;
v.pb(i);
}
if(fl==-1){
cout<<-1<<endl;
continue;
}
for(int j=0;j<v.size();j++){
ll i=v[j];
//cout<<"! "<<i<<" "<<d[i]<<endl;
if(i!=d[i]){
if(d[n-i+1]==i){
g.push({i,d[i]});
}else{
res.push({d[i],i});
ll x=d[i];
ll y=i;
swap(d[y],d[x]);
swap(d[n-y+1],d[n-x+1]);
v.pb(min(i,n-i+1));
}
}
}
if(g.size()%2==1){
cout<<-1<<endl;
continue;
}
while(g.size()>0){
ll m1=g.front().fr;
ll x=g.front().sc;
g.pop();
ll y=g.front().fr;
g.pop();
res.push({m1,y});
res.push({y,x});
}
cout<<res.size()<<" "<<res.size()<<endl;
while(res.size()>0){
cout<<res.front().fr<<" "<<res.front().sc<<endl;
res.pop();
}
}
return 0;
}
Compilation message (stderr)
cat.cpp: In function 'int main()':
cat.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j=0;j<v.size();j++){
| ~^~~~~~~~~
# | 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... |