0分求助!
查看原帖
0分求助!
574215
OneLeft楼主2022/5/31 19:03
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,sum;
map<long long,long long>x;
map<long long,long long>::iterator it,t1,t2;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		if(a==1)
		{
			if(x[b]==1)cout<<"Already Exist\n";
			else x[b]=1,sum++;
		}
		else if(sum==0)
			cout<<"Empty\n";
		else
		{
			if(x[b]==1)
			{
				cout<<b<<"\n";
				x.erase(b);
			}
			else
			{
				x[b]=1;
				it=x.find(b);
				t1=++it;
				t2=--it;
				if(it==x.begin())
				{
					cout<<t1->first<<"\n";
					x.erase(b);
				}
				else if(t1==x.end())
				{
					cout<<t2->first<<"\n";
					x.erase(b);
				}
				else
				{
					if(t1->first-b>b-t2->first)
					{
						cout<<t2->first<<"\n";
						x.erase(b);
					}
					else
					{
						cout<<t1->first<<"\n";
						x.erase(b);
					}
				}
			}
			sum--;
		}
	}
	
	return 0;
}

rt

2022/5/31 19:03
加载中...