萌新就差照搬题解了,为啥样例过了全wa啊,求助啊啊啊
查看原帖
萌新就差照搬题解了,为啥样例过了全wa啊,求助啊啊啊
619291
khMakarov楼主2022/2/10 21:15
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int n, k, x;
map<int, int> a;
int main() {
	cin >> n;
	while (n--) {
		cin >> k >> x;
		if (k == 1) {
			if (a.count(x))cout << "Already Exist" << endl;
			else a[x] = 1;
		}
		else {
			if (a.empty())cout << "Empty" << endl;
			else if (a.count(x)) {
				cout << x << endl;
				a.erase(x);
			}
			else {
				a[x] = 1;
				map<int, int>::iterator it1, it2;
				it1 = a.find(x);
				it2 = it1;
				it1++;
				if (it2 == a.begin())cout << it1->first << endl, a.erase(it1);
				else if (it1 == a.end())cout << (it2--)->first << endl, a.erase(it2--);
				else if (x - (--it2)->first > it1->first - x) {
					cout << it1->first << endl;
					a.erase(it1);
				}
				else {
					cout << it2->first << endl;
					a.erase(it2);
				}
				a.erase(x);
			}
		}
	}
	return 0;
}
2022/2/10 21:15
加载中...