rt,在本地测试样例过了,但是提交上去全 WA,求助各位大神!
#include <iostream>
#include <set>
#include <algorithm>
#include <cmath>
int main() {
std::cin.tie(0)->sync_with_stdio(false);
std::cout.tie(0);
int n, op, len;
std::set<int>::iterator it, newit;
std::set<int> s;
for (std::cin >> n; n; n--) {
std::cin >> op >> len;
if (op == 1) {
if (s.find(len) != s.end()) {
std::cout << "Already Exist\n";
continue;
}
s.insert(len);
} else {
it = newit = s.end();
it = s.lower_bound(len);
if (it == s.end()) {
std::cout << "Empty\n";
continue;
}
if (*it == len) {
std::cout << len << '\n';
s.erase(it);
continue;
}
newit = it;
for (int i = 0; i < 2; i++)
if (newit != s.begin()) newit--;
if (abs(*it - len) < abs(*newit - len)) {
std::cout << *it << '\n';
s.erase(it);
} else {
std::cout << *newit << '\n';
s.erase(newit);
}
}
}
std::cout.flush();
return 0;
}