Submission #391993

#TimeUsernameProblemLanguageResultExecution timeMemory
391993MahdiBahramianSwap (BOI16_swap)C++11
0 / 100
3 ms4940 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; const int Max = 2e5 + 10; int A[Max] , P[Max]; vector<int> N[Max]; int main() { int n; cin >> n; for(int i = 1 ; i <= n ; i++) cin >> A[i] , P[A[i]] = i , N[A[i]].pb(A[i / 2]) , N[A[i / 2]].pb(A[i]); for(int x = 1 ; x <= n ; x++) { int mnpos = P[x]; for(int u : N[x]) if(u > x) mnpos = min(mnpos , P[u]); if(mnpos < P[x]) { int i = P[x] , j = mnpos; swap(A[i] , A[j]); swap(P[A[i]] , P[A[j]]); } } for(int i = 1 ; i <= n ; i++) cout << A[i] << ' '; }
#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...