提交时间:2024-01-23 16:54:03

运行 ID: 125416

#include<iostream> #include<algorithm> using namespace std; const int N = 1e7 + 10; int n, a[N], t; void output(int x){ cout << a[x] << ' '; if(a[x * 2] != 0) output(x * 2); if(a[x * 2 + 1] != 0) output(x * 2 + 1); } void push(int x, int q){ if(a[x] == 0) {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++){ cin >> t; push(1, t); } output(1); return 0; }