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>
#ifdef local
#define debug(args...) qqbx(#args, args)
template <typename ...T> void qqbx(const char *s, T ...args) {
int cnt = sizeof...(T);
(std::cerr << "(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\n")));
}
#else
#define debug(...) ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> p(n), pos(n/2);
vector<pair<int,int>> ans;
for(int i = 0; i < n; i++) cin >> p[i], --p[i];
for(int i = 0; i < n; i++) if(p[i] < n/2) pos[p[i]] = i;
for(int i = 0; i < n/2; i++) {
if(p[i] != i) {
int j = pos[i];
swap(pos[p[i]], pos[p[j]]);
swap(p[i], p[j]);
swap(p[n-1-i], p[n-1-j]);
ans.pb(i, j);
}
/* for(int j = 0; j < n; j++) cerr << p[j]+1 << (j+1==n ? '\n' : ' '); */
}
if(!is_sorted(all(p))) return cout << -1 << '\n', void();
cout << ans.size() << ' ' << ans.size() << '\n';
for(auto [a, b]: ans) cout << a+1 << ' ' << b+1 << '\n';
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while(t--) solve();
}
Compilation message (stderr)
cat.cpp: In function 'void solve()':
cat.cpp:35:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | for(auto [a, b]: ans) cout << a+1 << ' ' << b+1 << '\n';
| ^
# | 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... |