求助,为什么全RE
查看原帖
求助,为什么全RE
1025958
511_Juruo_wyk楼主2024/8/10 16:00
#include<bits/stdc++.h>
using namespace std;
int n,s,x;
set<int>a;
int main(){
    cin>>n;
    while(n--){
        scanf("%d %d",&s,&x);
        if(s==1){if(!a.insert(x).second)puts("Already Exist");}
        else{
            if(a.empty())puts("Empty");
            else if(a.find(x)!=a.end()){
                cout<<x<<'\n'; 
                a.erase(a.find(x));
            }
            else{
                set<int>::iterator r=a.lower_bound(x);
                set<int>::iterator l=--r;++r;
                if(r==a.end()){
                    cout<<*l<<'\n';
                    a.erase(l);
                }
                else if(r==a.begin()){
                    cout<<*r<<'\n';
                    a.erase(r);
                }
                else if(x-(*l)<=(*r)-x){
                    cout<<*l<<'\n';
                    a.erase(l);
                }
                else{
                    cout<<*r<<'\n';
                    a.erase(r);
                }
            }
        }
    }
	return 0;
}
2024/8/10 16:00
加载中...