AcWing 3595. 二叉排序树
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e2 + 10;
int t, n, m, k, l, r, op, x, y;
int le[N], ri[N], f[N], idx;
void findpa(int r, int x) {
if (f[x] > f[r]) {
if (ri[r] == 0) {
ri[r] = x;
cout << f[r] << "\n";
return;
}
findpa(ri[r], x);
} else {
if (le[r] == 0) {
le[r] = x;
cout << f[r] << "\n";
return;
}
findpa(le[r], x);
}
}
void solve() {
cin >> n;
cin >> f[++idx];
cout << -1 << "\n";
while (--n) {
cin >> f[++idx];
findpa(1, idx);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}