This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |