CCCPaste

Untitled

#include 
using namespace std;
typedef long long ll;
int main()
{ 
    int n;
    cin >> n;
    ll res = LLONG_MAX;
    set st;
    for(int i = 0; i < n; i++) {
      int tip;
      cin >> tip;

      if(tip == 1) {
        ll x;
        cin >> x;
        st.insert(x);

        auto it = st.lower_bound(x);
        if(it != st.begin()) {
          it--;
          res = min(res, x - *it);
          it++;
        }
        it++;
        if(it != st.end()) {
          res = min(res, *it - x);
        }

      }
      else {
        cout << res << endl;
      }
    }
    return 0;
}