Submission #1152142

#TimeUsernameProblemLanguageResultExecution timeMemory
1152142KluydQCat (info1cup19_cat)C++20
51.25 / 100
287 ms25900 KiB
#include <bits/stdc++.h> //#include "grader.h" #define respagold ios_base::sync_with_stdio(0), cin.tie(0); #define int long long #define ll long long #define int2 __int128_t #define FOR( i, x, n, d ) for( int i = x; i <= n; i += d ) #define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d ) #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) (int)(x.size()) #define pb push_back #define ins insert #define lb lower_bound #define ub upper_bound #define pii pair <int, int> #define mkp make_pair using namespace std; const int N1 = 2e5 + 123; int a[N1], b[N1], c[N1], n, m, k, z, w, ans, x, y, pos[N1]; vector <pii> v; mt19937 rng( chrono::steady_clock::now().time_since_epoch().count()); int rand( int l, int r ) { uniform_int_distribution <int> uid( l, r ); return uid( rng ); } void swp( int i, int j ) { swap( a[i], a[j] ); pos[a[i]] = i, pos[a[j]] = j; } void solve() { cin >> n; v.clear(); k = 0; FOR( i, 1, n, 1 ) cin >> a[i], b[i] = 0; FOR( i, 1, n, 1 ) { if( a[i] != n - a[n - i + 1] + 1 ) { cout << "-1\n"; return; } } FOR( i, 1, n, 1 ) { pos[a[i]] = i; if( i <= (n >> 1) && a[i] > a[n - i + 1] ) k ++, b[i] = b[n - i + 1] = 1; } if( k % 2 ) { cout << "-1\n"; return; } FOR( i, 1, n >> 1, 1 ) { int ps = pos[i]; if( ps == i || ps == n - i + 1 ) continue; int i1 = i, j1 = ps, i2 = n - i + 1, j2 = n - ps + 1; if( (j1 < j2 && a[j1] > a[j2]) || (j1 > j2 && a[j1] < a[j2]) ) swap(j1, j2); v.pb({ i1, j1 }), swp( i1, j1 ), swp( i2, j2 ); } vector <pii> po; FOR( i, 1, n >> 1, 1 ) { if( a[i] > a[n - i + 1] ) po.pb({ i, n - i + 1 }); } FOR( i, 0, sz(po) - 1, 2 ) { v.pb({ po[i].F, po[i + 1].S }); v.pb({ po[i].F, po[i + 1].F }); } cout << sz(v) << ' ' << sz(v) << '\n'; for( auto i : v ) cout << min( i.F, i.S ) << ' ' << max( i.F, i.S ) << '\n'; } signed main() { // freopen("connect.in", "r", stdin); // freopen("connect.out", "w", stdout); respagold int test = 0; if( !test ) cin >> test; while( test -- ) { solve(); } } // solved by KluydQ
#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...