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 <iostream>
#include <vector>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
using namespace std;
const int maxN = 3e6 + 326;
int N, arr[maxN], T;
bool vis[maxN];
inline void makeMove(int i, int j){
swap(arr[i], arr[j]);
swap(arr[N - i + 1], arr[N - j + 1]);
}
inline void disp(){
for(int i = 1; i <= N; i++) cout << arr[i] << " \n"[i == N];
}
inline void solve(){
cin >> N;
for(int i = 1; i <= N; i++) cin >> arr[i];
for(int i = 1; i <= N / 2; i++) if(arr[i] + arr[N - i + 1] != N + 1){
cout << -1 << endl;
return;
}
vector<int> pos = vector<int>();
vector<pii> ans = vector<pii>();
for(int i = 1; i <= N / 2; i++) if(arr[i] > arr[N - i + 1]) pos.push_back(i);
if(pos.size() & 1){ //not sure about this
cout << -1 << endl;
return;
}
/*
cout << "have: ";
for(int x : pos) cout << x << " ";
cout << endl;
*/
for(int i = 0; i < pos.size(); i += 2){
makeMove(pos[i], N - pos[i + 1] + 1);
ans.emplace_back(pos[i], N - pos[i + 1] + 1);
}
disp();
fill(vis, vis + N + 1, false);
for(int i = 1; i <= N / 2; i++){
while(i != arr[i]){
int nxt = arr[i];
makeMove(i, arr[i]);
ans.emplace_back(i, nxt);
disp();
}
}
cout << ans.size() << " " << ans.size() << endl;
for(auto [a, b] : ans) cout << a << " " << b << endl;
}
int main(){
//ericxiao
cin >> T;
while(T--){
solve();
}
}
Compilation message (stderr)
cat.cpp: In function 'void solve()':
cat.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < pos.size(); i += 2){
| ~~^~~~~~~~~~~~
cat.cpp:59:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
59 | for(auto [a, b] : ans) cout << a << " " << b << endl;
| ^
# | 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... |