提交记录 28102
提交时间 |
评测时间 |
2025-05-23 21:07:02 |
2025-05-23 21:07:04 |
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define int long long
#define inf (1ll << 62)
constexpr int N=1e5+7;
int m[N];
int tot;
int n;
void repaira(int x){
if(x==1||m[x/2]<m[x]) return;
swap(m[x],m[x/2]);
repaira(x/2);
}
void repairb(int x){
if(x*2>tot) return ;
int tmp=x*2;
if(x*2+1<=tot) tmp=(m[x*2]<m[x*2+1]?x*2:x*2+1);
if(m[x]>m[tmp]){
swap(m[x],m[tmp]);
repairb(tmp);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>m[++tot];
repaira(tot);
}
for(int i=1;i<=n;i++){
cout<<m[1]<<" ";
swap(m[1],m[tot--]);
repairb(1);
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 44.49 us | 60 KB | Accepted | Score: 100 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2025-06-01 22:43:15 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠