map,60分,求条
查看原帖
map,60分,求条
1009958
niuniudundun楼主2024/10/5 13:33
#include<iostream>
#include<map>
using namespace std;
map<int,bool> m;
int n,maxn=-1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int t,length;
		cin>>t>>length;
		if(t==1){
			if(m.count(length)==true){
				cout<<"Already Exist"<<endl;
			}else{
				m[length]=true;
			}
			if(maxn<length){
				maxn=length;
			}
		}else{
			if(m.empty()){
				cout<<"Empty"<<endl;
			}else{
				int j=length,k=length;
				while(j>=0||k<=maxn){
					if(m.count(j)==true){
						cout<<j<<endl;
						m.erase(j);
						break;
					}else if(m.count(k)==true){
						cout<<k<<endl;
						m.erase(k);
						break;
					}else{
						if(j!=0) j--;
						if(k!=maxn) k++;
					}
				}
			}
		}
//		cout<<m.size()<<"//"<<endl;
	}
	return 0;
}

AC#1#2#3,TLE#4#5

2024/10/5 13:33
加载中...