#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) cerr << "Line: " << __LINE__, kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
int n;
vector<int> a,vis, b;
vector<pii> ans;
void init_(int _n) {
n = _n;
ans.clear();
a.assign(n + 1, 0);
vis.assign(n + 1, 0);
}
void solve() {
int cnt = 0;
rep(i, n / 2 + 1, n) a[i] = n - a[i] + 1;
rep(i, 1, n / 2) {
if(a[i] != a[n - i + 1]) {
cout << "-1\n";
return;
}
}
rep(i, 1, n / 2) if(a[i] != i && !vis[i]) {
int cur = a[i];
b.clear(), b.push_back(i);
vis[i] = 1;
while(cur != i) {
b.push_back(cur);
vis[cur] = 1;
cur = a[cur];
assert(b.size() <= n);
}
rrep(j, 0, signed(b.size()) - 2) {
ans.push_back({b[j], b[j + 1]});
swap(a[b[j]], a[b[j + 1]]);
swap(a[n - b[j] + 1], a[n - b[j + 1] + 1]);
}
}
cout << ans.size() << " " << ans.size() << "\n";
for(auto i : ans) {
cout << i.first << " " << i.second << "\n";
}
return;
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int t; cin >> t;
while(t--) {
int n; cin >> n;
init_(n);
rep(i, 1, n) cin >> a[i];
solve();
}
return 0;
}
Compilation message
cat.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
cat.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
| ^~~~
cat.cpp:20:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
| ^~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from cat.cpp:2:
cat.cpp: In function 'void solver::solve()':
cat.cpp:54:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
54 | assert(b.size() <= n);
| ~~~~~~~~~^~~~
cat.cpp:38:7: warning: unused variable 'cnt' [-Wunused-variable]
38 | int cnt = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
928 KB |
Output is correct |
2 |
Correct |
24 ms |
956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
928 KB |
Output is correct |
2 |
Correct |
24 ms |
956 KB |
Output is correct |
3 |
Correct |
559 ms |
18004 KB |
Output is correct |
4 |
Correct |
529 ms |
17204 KB |
Output is correct |
5 |
Correct |
557 ms |
21292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |