WA40pts求条
查看原帖
WA40pts求条
1385113
LiQiRong__juruo楼主2025/7/29 15:21

rt

#include <bits/stdc++.h>
using namespace std;
set<int> a;
int main(){
    int m;
    cin >> m;
    for(int i = 1;i <= m;i++){
        int op;
        cin >>op;
        if(op == 1){
            int x;
            cin >>x;
            if(a.find(x) == a.end()){
                a.insert(x);
            }else{
                cout << "Already\n";
            }
            
        }else{
            int x;
            cin >> x;
            if(a.empty()){
                cout << "Empty\n";
            }else{
                if(a.find(x) != a.end()){
                    cout <<x<<'\n';
                    a.erase(x);
                    continue;
                }
                auto it1 = a.lower_bound(x),it2 = it1;
                if(it1 != a.begin())it2--;
                else {
                    cout <<*it1<<'\n';
                    a.erase(it1);
                    continue;
                }
                if(abs(x - (*it2)) > abs((*it1) - x)){
                    cout << *it1<<'\n';
                    a.erase(it1);
                }else{
                    cout <<*it2<<'\n';
                    a.erase(it2);
                }
            }
        }
    }
}
2025/7/29 15:21
加载中...