提交时间:2024-01-23 16:55:32

运行 ID: 125427

#include<iostream> #include<algorithm> 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){ if(a[x] == (int)1e9) {a[x] = q; return;} if(a[x] > q) push(x * 2, q); else if(a[x] < q) push(x * 2 + 1, 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; }