大佬们,请问这么写,问题出在哪里
查看原帖
大佬们,请问这么写,问题出在哪里
1604276
handless楼主2025/1/7 21:39
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
const LL INF = 1e10+10;
set<LL> mp;
int main()
{
	mp.insert(-INF),mp.insert(INF);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		LL op,x;
		cin >> op >> x;
		if(op==1)
		{
			if(mp.count(x))
			{
				cout << "Already Exist" <<endl;
			}
			else
			{
				mp.insert(x);
			}
		}
		else
		{
			if(mp.size()==2)
			{
				cout << "Empty" <<endl;
				continue;
			}
			else
			{
				if(mp.count(x))
				{
					cout << x << endl;
					mp.erase(x);
				}
				else
				{
					auto it1 = mp.lower_bound(x);
					auto it2 = it1;
					it2--;
					LL t = min(abs(*it1-x),abs(*it2-x));
					cout << t << endl;
					mp.erase(t);
				}
			}
		}
	}
	return 0;
}
2025/1/7 21:39
加载中...