#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 3e6+10;
int N;
int arr[mxn],pos[mxn];
void change(int a,int b){
swap(pos[arr[a]],pos[arr[b]]);
swap(arr[a],arr[b]);
a = N-a+1,b = N-b+1;
swap(pos[arr[a]],pos[arr[b]]);
swap(arr[a],arr[b]);
return;
}
void solve(){
cin>>N;
for(int i = 1;i<=N;i++)cin>>arr[i],pos[arr[i]] = i;
vector<pii> ans;
for(int i = 1;i<=N;i++){
if(pos[arr[i]] = i)continue;
int a = i,b = pos[arr[i]];
change(a,b);
}
for(int i = 1;i<=N;i++){
if(arr[i] != i){
cout<<"-1\n";
return;
}
}
cout<<ans.size()<<' '<<ans.size()<<'\n';
for(auto &i:ans)cout<<i.fs<<' '<<i.sc<<'\n';
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)solve();
}
Compilation message
cat.cpp: In function 'void solve()':
cat.cpp:30:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
30 | if(pos[arr[i]] = i)continue;
| ~~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2904 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2904 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |