13920

                Never    
C++
       
#include<iostream>
#include<set>
#include<cmath>
using namespace std;
int main(){
    set<int> s;
    int N,tmp;
    cin >> N;
    while(N--){
        cin >> tmp;
        if(tmp==1){
            cin >> tmp;
            auto i = s.find(tmp);
            if(i!=s.cend()) s.erase(i);
            else s.insert(tmp);
        }
        else if(tmp==2){
            cin >> tmp;
            auto a=s.lower_bound(tmp);
            if(a==s.cend()||(a==s.cbegin()&&*a!=tmp)){
                cout << "-1\n";
            }
            else if(a==s.cbegin()&&*a==tmp){
                auto b = a;b++;
                if(b==s.cend()) cout << "-1\n"; //tmp exists, but only one number
                else cout << *b - *a << endl; //tmp exists and is segment's left bound
            }
            else{
                auto b = a;b--;
                cout << *a - *b << endl; //tmp exists and is segemnt's right bound
            }
        }
    }
    return 0;
}

Raw Text