You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
795 B
27 lines
795 B
#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;
|
|
} |