-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
46 lines (40 loc) · 783 Bytes
/
Copy pathtest.cpp
File metadata and controls
46 lines (40 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int a[N];
void push_down(int u, int size){
int t=u, l=t*2, r=t*2+1;
if(l<=size && a[l]>a[t]) t = l;
if(r<=size && a[r]>a[t]) t = r;
if(t != u){
swap(a[t], a[u]);
push_down(t, size);
}
}
void push_up(int u){
while(u/2 && a[u/2] < a[u]){
swap(a[u], a[u/2]);
u/=2;
}
}
void insert(int size, int x){
a[size++] = x;
push_up(size);
}
int get(){
return a[1];
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int size = n;
for(int i=1;i<=n;i++) push_up(i);
for(int i=1;i<=n;i++){
swap(a[1], a[size--]);
push_down(1, size);
}
for(int i=1;i<=n;i++) cout<<a[i];
cout<<endl;
return 0;
}