Pagini recente » Cod sursa (job #1194439) | Cod sursa (job #2290519) | Cod sursa (job #2325231) | Cod sursa (job #2160775) | Cod sursa (job #2090962)
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
const int dirx[] = {-2,-1,1,2, 1, -1};
const int diry[] = {0,1,1,0, -1, -1};
inline void debugMode() {
#ifndef ONLINE_JUDGE
freopen("algsort.in", "r", stdin);
freopen("algsort.out", "w", stdout);
#endif
}
int n, m, a[500100], AINT[2000100];
void update(int Node, int Left, int Right, int Pos){
if (!(Right - Left)){
AINT[Node] = Pos;
return ;
}
int mid = (Left + Right) >> 1;
if (Pos <= mid) update(Node << 1, Left, mid, Pos);
else update(Node << 1 | 1, mid + 1, Right, Pos);
int idx1 = AINT[Node << 1], idx2 = AINT[Node << 1 | 1];
AINT[Node] = (a[idx1] < a[idx2] ? idx1 : idx2);
}
int main(){
debugMode();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
update(1, 1, n, i);
}
for (int i = 1; i <= n; i++){
cout << a[ AINT[1] ] << " ";
a[ AINT[1] ] = INT_MAX;
update(1, 1, n, AINT[1]);
}
return 0;
}