求助
查看原帖
求助
303782
Thir楼主2020/5/6 23:49

样例过了,但是全WE。。

#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int n, k, s;
set<int> stt;
int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> k;
        if (k == 1)
        {
            cin >> s;
            auto iter = stt.find(s);
            if (iter != stt.end())
                cout << "Already Exist" << endl;
            else
                stt.insert(s);
        }
        else
        {
            if (stt.empty()==true)
            {
                cout << "Empty" << endl;
                continue;
            }
            cin >> k;
            auto iter1 = stt.lower_bound(k);
            auto iter2 = iter1;
            if (iter2 != stt.begin())
                iter2--;
            if (iter1 != stt.end() && (k - (*iter2) > (*iter1 - k)))
                iter2 = iter1;
            cout << *iter2 << endl;
            stt.erase(iter2);
        }
    }
    return 0;
}
2020/5/6 23:49
加载中...