Files
python/TangDou/LuoGuBook/P5250.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

27 lines
795 B
C++

#include <bits/stdc++.h>
using namespace std;
int n; //n次操作
int opt; //操作指令
int length; //木材长度
set<int> ds; //集合,红黑树,平衡二叉树
int main() {
cin >> n;
while (n--) {
cin >> opt >> length;
if (opt == 1) {
if (ds.find(length) != ds.end()) cout << "Already Exist" << endl;
else ds.insert(length);
} else if (ds.empty())
cout << "Empty" << endl;
else {
auto i = ds.lower_bound(length), j = i; //复制出来一个迭代器j
if (j != ds.begin()) j--;//前一个
if (i != ds.end() && length - (*j) > (*i) - length) j = i;
cout << (*j) << endl;
ds.erase(j);
}
}
return 0;
}