NKTREE - Cây nhị phân tìm kiếm
Tác giả: ladpro98
Ngôn ngữ: C++
#include <bits/stdc++.h>
const long long INF = (long long)1e15;
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
long long low = -INF, high = INF;
long long x, lastX; bool first = 1;
while (cin >> x) {
if (x <= low || high <= x) {
cout << "NO\n";
return 0;
}
if (!first) {
if (x == lastX) {
cout << "NO\n";
return 0;
}
if (x < lastX)
high = min(high, lastX);
else
low = max(low, lastX);
}
lastX = x;
if (first) first = 0;
}
cout << "YES\n";
return 0;
}