RT,要不就WA要不就RE。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#define int long long
using namespace std;
int t;
set<int> s;
signed main(){
cin>>t;
while(t--){
int opt,x;
cin>>opt>>x;
if(opt==1){
if(s.find(x)==s.end()){
s.insert(x);
}
else cout<<"Already Exist"<<endl;
}
else{
if(s.empty()){
cout<<"Empty"<<endl;
}
else{
auto y=s.lower_bound(x);
if(y==s.end()){
cout<<*(--y)<<endl;
s.erase(--y);
}
// else if(y==s.begin()){
// cout<<*y<<endl;
// s.erase(y);
// }
else if(*y==x){
cout<<x<<endl;
s.erase(y);
}
else{
auto a=--y,b=y;
int ac=abs(*a-x),bc=abs(*b-x),ans;
if(ac<=bc){
ans=*a;
s.erase(a);
}
else{
ans=*b;
s.erase(b);
}
cout<<ans<<endl;
}
}
}
}
return 0;
}