set 0分求调,救救孩子吧
查看原帖
set 0分求调,救救孩子吧
652816
saixingzhe楼主2023/1/29 15:46
#include<bits/stdc++.h>
using namespace std;
long long n,op,s;
set <long long> st;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&op,&s);
		if(op==1){
			long long w=st.size();
			st.insert(s);
			if(st.size()==w)	printf("Already Exist\n");
		}
		else{
			if(st.empty()){
				printf("Empty\n");
				continue;
			}	
			auto B=st.lower_bound(s),E=prev(st.lower_bound(s));
			//printf("%d %d\n",(*B),(*E));
			if(abs(s-(*B))<abs(s-(*E)))	cout<<(*B)<<endl,st.erase((*B));
			else	cout<<(*E)<<endl,st.erase((*E));	
				
		}
	}
	return 0;
}
2023/1/29 15:46
加载中...