Submission #475023

#TimeUsernameProblemLanguageResultExecution timeMemory
475023hhhhauraCat (info1cup19_cat)C++14
100 / 100
603 ms15748 KiB
#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()
using namespace std;
#define pii pair<int, int>
#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, b, vis;
	vector<pii> ans;
	void init_(int _n) {
		n = _n;
		a.assign(n + 1, 0);
		b.assign(n + 1, 0);
		ans.clear();
	}
	void sswap(int x, int y) {
		ans.push_back({x, y});
		swap(a[x], a[y]);
		swap(a[n - x + 1], a[n - y + 1]);
	}
	int get(int x) {
		return x > n / 2 ? n - x + 1: x;
	}
	void solve() {
		int cnt = 0;
		rep(i, 1, n / 2) {
			if(a[i] + a[n - i + 1] != n + 1) {
				cout << "-1\n";
				return;
			}
			if(a[i] > n / 2) cnt ++;
		}
		if(cnt & 1) {
			cout << "-1\n";
			return;
		}
		vector<int> temp;
		vis.assign(n + 1, 0);
		int pre = 0;
		rep(i, 1, n / 2) if(!vis[i]) {
			temp.clear(), vis[i] = 1;
			if(a[i] > n / 2) temp.push_back(i);
			for(int j = get(a[i]); j != i; j = get(a[j])) {
				if(a[j] > n / 2) temp.push_back(j);
				vis[j] = 1;
			}
			if(temp.size() % 2 == 1) {
				if(pre) sswap(pre, n - temp.back() + 1), pre = 0;
				else pre = temp.back();
				temp.pop_back();
			}
			for(int j = 0; j < temp.size(); j += 2) 
				sswap(temp[j], n - temp[j + 1] + 1);
		}
		vis.assign(n + 1, 0);
		rep(i, 1, n / 2) if(!vis[i]) {
			temp.clear(), vis[i] = 1;
			temp.push_back(i);
			for(int j = get(a[i]); j != i; j = get(a[j])) {
				temp.push_back(j), vis[j] = 1;
			}
			for(int j = signed(temp.size()) - 1; j > 0; j --) 
				sswap(temp[j], temp[j -1]);
		}
		cout << ans.size() << " " << ans.size() << "\n";
		for(auto i : ans) cout << i.first << " " << i.second << "\n";
	}
};
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 (stderr)

cat.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
cat.cpp:12:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   12 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
      |             ^~~~
cat.cpp:12:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   12 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
      |                     ^~~~
cat.cpp: In function 'void solver::solve()':
cat.cpp:65:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |    for(int j = 0; j < temp.size(); j += 2)
      |                   ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...