样例过来,全wa了QAQ
查看原帖
样例过来,全wa了QAQ
1548725
xiaII楼主2025/1/6 16:58
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
int n; set<int>s;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int op, len;
		cin >> op >> len;
		if (op == 1) {
			int z = s.size();
			s.insert(len);
			if (s.size() == z) {
				cout << "Already Exist" << endl;
			}
		}
		else {
			if (s.empty()) {
				cout << "Empty" << endl;
			}
			else if (s.size() == 1) {
                cout << *s.begin() << endl;
				s.erase(s.begin());
			}
			else {
				int z = s.size();
				s.erase(len);
				if (z == s.size()) {
                    auto w = s.upper_bound(len);
                    if (w == s.end()) {
						w--;
						cout << *w << endl;
						s.erase(*w);
                    }
					else {
						int xx = *w; w--;
						int yy = *w;
						s.erase(abs(yy - len) <= abs(xx - len) ? yy : xx);
						cout << (abs(yy - len) <= abs(xx - len) ? yy : xx) << endl;
					}
					continue;
				}
				cout << len << endl;
			}
		}
	}
	return 0;
}
2025/1/6 16:58
加载中...