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>
using namespace std;
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 200005;
int N, p[MXN];
int n;
vector<pii> ans;
void SORT() {
FOR(i, 1, n + 1) {
if (p[i] == i) continue;
while (p[i] != i) {
ans.emplace_back(i, p[i]);
swap(p[i], p[p[i]]);
}
}
}
void COUT() {
cout << ans.size() << ' ' << ans.size() << '\n';
for (auto &i : ans) cout << i.fs << ' ' << i.sc << '\n';
}
namespace SB24 {
void solve() {
SORT();
COUT();
}
}
void solve() {
vector<int> w;
FOR(i, 1, n + 1) {
if (p[i] > p[N - i + 1]) {
w.push_back(i);
swap(p[i], p[N - i + 1]);
}
}
if (w.size() % 2) {
cout << -1 << '\n';
return;
}
for (int i = 0; i < w.size(); i += 2) {
ans.emplace_back(w[i], N - w[i + 1] + 1);
swap(p[w[i]], p[w[i + 1]]);
}
SORT();
COUT();
}
void miku() {
cin >> N;
n = N / 2;
FOR(i, 1, N + 1) cin >> p[i];
FOR(i, 1, n + 1) {
if (p[i] + p[N - i + 1] != N + 1) {
cout << -1 << '\n';
return;
}
}
if (*max_element(p, p + n) <= n) {
SB24::solve();
return;
}
solve();
}
void RESET() {
ans.clear();
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t;
cin >> t;
while (t--) {
miku();
RESET();
}
return 0;
}
Compilation message (stderr)
cat.cpp: In function 'void solve()':
cat.cpp:51:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0; i < w.size(); i += 2) {
| ~~^~~~~~~~~~
# | 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... |