Submission #762929

#TimeUsernameProblemLanguageResultExecution timeMemory
762929TrunktyCat (info1cup19_cat)C++14
100 / 100
416 ms20728 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll int t; int n; int arr[200005],pos[200005]; int val(int x){ if(x>n/2){ return n-x+1LL; } else{ return x; } } signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> t; for(int e=1;e<=t;e++){ cin >> n; for(int i=1;i<=n;i++){ cin >> arr[i]; } bool bad = false; for(int i=1;i<=n/2;i++){ if(arr[i]+arr[n-i+1LL]!=n+1LL){ bad = true; } } if(bad){ cout << -1 << "\n"; continue; } for(int i=1;i<=n/2;i++){ pos[val(arr[i])] = i; } vector<vector<int>> ans; for(int i=1;i<=n/2;i++){ if(pos[i]!=i){ if(arr[pos[i]]>n/2){ int x = pos[i]; arr[x] = n-arr[x]+1LL; arr[i] = n-arr[i]+1LL; swap(arr[i],arr[x]); ans.push_back({i,n-x+1LL}); pos[val(arr[i])] = i; pos[val(arr[x])] = x; } else{ int x = pos[i]; swap(arr[i],arr[x]); ans.push_back({i,x}); pos[val(arr[i])] = i; pos[val(arr[x])] = x; } } } int bef=-1; for(int i=1;i<=n/2;i++){ if(arr[i]>n/2){ if(bef==-1){ bef = i; } else{ ans.push_back({bef,i}); ans.push_back({bef,n-i+1LL}); bef = -1; } } } if(bef!=-1){ cout << -1 << "\n"; } else{ cout << ans.size() << " " << ans.size() << "\n"; for(vector<int> i:ans){ cout << i[0] << " " << i[1] << "\n"; } } } return 0; }
#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...