为啥测试点能过,在线IDE也没问题,结果提交全是运行时错误呢
查看原帖
为啥测试点能过,在线IDE也没问题,结果提交全是运行时错误呢
488371
Lixp楼主2021/7/30 15:25
#include<bits/stdc++.h>
using namespace std;

int main()
{
	map<int,int> m;
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==1)
			if(!m.count(b))
				m[b]=1;
			else printf("Already Exist\n");
		else 
		{
			if(m.empty()) cout<<"Empty"<<endl;
			else if(m.count(b))
			{
				printf("%d\n",b);
				m.erase(b);
			}
			else
			{
				m[b]=1;
				auto t1 = m.find(b);
				auto t2 = t1;
				if(t2==m.begin())
				{
					t1++;
					cout<<(t1->first)<<endl;
					m.erase(t1);m.erase(t2);
				}
				else if(t2==m.end())
				{
					t1--;
					cout<<(t1->first)<<endl;
					m.erase(t2);m.erase(t1);
				}
				else 
				{
					auto t3 = t2;
					t3++;
					t1--;
					int r1 = t3->first - t2->first;
					int r2 = t2->first - t1->first;
					if(r1<r2)
					{
						cout<<t3->first<<endl;
						m.erase(t3);m.erase(t2);
					}
					else if(r2<=r1)
					{
						cout<<t1->first<<endl;
						m.erase(t1);m.erase(t2);
					}
				}
			}
		}
	}	
	return 0;
} 
2021/7/30 15:25
加载中...