提交时间:2024-01-23 17:06:01
运行 ID: 125514
#include<iostream> using namespace std; const int N = 1e5 + 10; int n, a[N], t; void output(int x){ cout << a[x] << ' '; if(a[x * 2] != (int)1e9) output(x * 2); if(a[x * 2 + 1] != (int)1e9) output(x * 2 + 1); } void push(int x, int q){ while(a[x] != (int)1e9){ if(a[x] > q) x *= 2; else if(a[x] < q) x = x * 2 + 1; } a[x] = q; } int main(){ cin >> n; for(int i = 1; i <= N; i++) a[i] = 1e9; for(int i = 1; i <= n; i++){ cin >> t; push(1, t); } output(1); return 0; }