求助 40分
查看原帖
求助 40分
499627
arc_suvr楼主2021/10/2 16:53
#include<bits/stdc++.h>
using namespace std;
set<int> S;
set<int>::iterator i,j;
int main()
{
	int n;
	cin>>n;
	for(int l=1;l<=n;l++)
	{
		int op,length;
		cin>>op>>length;
		if(op==1)
			S.insert(length);
		if(op==2)
		{
			if(S.empty())
				cout<<"Empty"<<endl;
			else if(S.count(length))
			{
				cout<<length<<endl;
				S.erase(length);
			}
			else 
			{ 
				i=S.lower_bound(length);
				j=i;
				if(j!=S.begin())
					j--;
				if(i!=S.end()&&length-(*j)>(*i)-length)
					j=i;
				cout<<(*j)<<endl; 
				S.erase(j);
			} 
		}			
	}	
	return 0;
} 
2021/10/2 16:53
加载中...