为什么我这个wa了
查看原帖
为什么我这个wa了
136889
wweiyi楼主2021/3/21 15:57
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
set <int> a;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int op,l;
		cin>>op>>l;
		if(op==1)
		{
			if(a.count(l)>0)
			cout<<"Already Exist"<<endl;
			else
			a.insert(l); 
		}
		if(op==2)
		{
			if(a.empty())
			{
				cout<<"Empty"<<endl;
				continue;
			}
			else if(a.count(l)>0)
			{
				cout<<l<<endl;
				a.erase(l);
				continue; 
			}
			int x=*(--a.lower_bound(l));
			int y=*a.upper_bound(l); 
			if(l-x<=y-l)
			{
				cout<<x<<endl;
				a.erase(x);
				continue;  
			}
			else
			{
				cout<<y<<endl;
				a.erase(y);
				continue;  
			}
		}
	}
	return 0;
}
2021/3/21 15:57
加载中...