Advertisement
Josif_tepe

Untitled

Jun 8th, 2024
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.     ll res = LLONG_MAX;
  9.     set<ll> st;
  10.     for(int i = 0; i < n; i++) {
  11.       int tip;
  12.       cin >> tip;
  13.  
  14.       if(tip == 1) {
  15.         ll x;
  16.         cin >> x;
  17.         st.insert(x);
  18.  
  19.         auto it = st.lower_bound(x);
  20.         if(it != st.begin()) {
  21.           it--;
  22.           res = min(res, x - *it);
  23.           it++;
  24.         }
  25.         it++;
  26.         if(it != st.end()) {
  27.           res = min(res, *it - x);
  28.         }
  29.  
  30.       }
  31.       else {
  32.         cout << res << endl;
  33.       }
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement