#include using namespace std; int n; //n次操作 int opt; //操作指令 int length; //木材长度 set 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; }