求调 set做法
查看原帖
求调 set做法
536617
AniuKarry楼主2023/7/12 23:59

rt```cpp #include <bits/stdc++.h> using namespace std; #define ll long long set l; const int inf=0x3f3f3f3f; const ll INF=0x7fffffff;

int main() { //

int n; cin>>n;
int leng;
set<int>::iterator check,f1,f2,f3;
for(int i=1;i<=n;i++)
{
	char p;cin>>p;
	if(p=='1')
	{
		cin>>leng;
		check=l.find(leng);
		if(check==l.end())
		{
			l.insert(leng);
			continue;
		}
		else
		{
			cout<<"Already Exist"<<endl;
			continue;
		}
	}
	else
	{
		cin>>leng;
		check=l.find(leng);
		if(l.size()==0)
		{
			cout<<"Empty"<<endl;
			continue;
		}
		else if(check!=l.end())
		{
			cout<<leng<<endl;
			l.erase(leng);
			continue;
		}
		else
		{
			f2=check;
			f1=check--;
			f3=check++;
			if(*f2-*f1<=*f3-*f2)
			{
				cout<<*f1<<endl;
				l.erase(*f1);
				continue;
			}
			else
			{
				cout<<*f3<<endl;
				l.erase(*f3);
				continue;
			}
		}
		
		l.erase(*f2);
		
	}
}

return 0;

} /* in1: 7 1 1 1 5 1 3 2 3 2 3 2 3 2 3 out1: 3 1 5 Empty */

2023/7/12 23:59
加载中...