STLset求助
查看原帖
STLset求助
457431
Li_wenjie楼主2022/4/1 23:10
#include<bits/stdc++.h>
using namespace std;
int main()
{
	set<int>s;
	int n;
	cin>>n;
	while(n--)
	{
		int k,x;
		cin>>k>>x;
		if(sk==1)
		{
			if(s.find(x)==s.end())
			s.insert(x);
			else cout<<"Already Exist"<<endl;
		}
		else if(k==2)
		{
			if(s.empty()) cout<<"Empty"<<endl;
			else
			{
				set<int>::iterator l=s.lower_bound(k),r=s.upper_bound(k);
				if(l!=s.begin())l--;
				if(abs(*l-x)>abs(*r-x)) 
				{
					cout<<*r<<endl;
					s.erase(r);
				}
				else 
				{
					cout<<*l<<endl;
					s.erase(l);
				}
				
			}
		}
	}
}
2022/4/1 23:10
加载中...