各位大佬,能把能帮帮我这个蒟蒻,真的非常噶感谢
查看原帖
各位大佬,能把能帮帮我这个蒟蒻,真的非常噶感谢
1051749
noi_onlyup楼主2024/8/3 15:37
#include <bits/stdc++.h>
using namespace std;
set <long long> st;
long long ans,n,x,y;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x>>y; 
		if(x==1){
			if(!binary_search(st.begin(),st.end(),y)) st.insert(y);
			else cout<<"Already Exist"<<endl;
		}
		else{
			if(!st.empty()){
				if(binary_search(st.begin(),st.end(),y)){
					cout<<y<<endl;
					st.erase(y);
				}
				else{
					auto ip=lower_bound(st.begin(),st.end(),y);
					if(ip==st.begin()){
						cout<<*st.begin()<<endl;
						st.erase(*st.begin());
					}
					else if(ip==st.end()){
						cout<<*--st.end()<<endl;
						st.erase(*--st.end());
					}
					else{
						auto ir=--ip;
						if(abs(y-(*ip))==abs(y-(*ir))){
							cout<<(*ir)<<endl;
							st.erase(ir);
						}
						else if(abs(y-(*ip))>abs(y-(*ir))){
							cout<<(*ir)<<endl;
							st.erase(ir);
						}
						else{ 
							cout<<(*ip)<<endl;
							st.erase(ip);
						}
					}
				}
			}
			else cout<<"Empty"<<endl;
			
		}
	}
	return 0;
}

我的样例是对的,输出换行没有问题,有没有人知道是错哪里了!!!谢谢!

2024/8/3 15:37
加载中...