Josif_tepe

Untitled

Mar 11th, 2026
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5. using namespace std;
  6. typedef long long ll;
  7. const ll INF = 2e18;
  8.  
  9. int main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.     int k;
  13.     cin >> k;
  14.    
  15.     ll res = INF;
  16.     set<ll> st;
  17.     for(int i = 0; i < k; i++) {
  18.         int tip;
  19.         cin >> tip;
  20.        
  21.         if(tip == 1) {
  22.             ll x;
  23.             cin >> x;
  24.             st.insert(x);
  25.            
  26.             auto it = st.lower_bound(x);
  27.             if(it != st.begin()) {
  28.                 it--;
  29.                 res = min(res, x - *it);
  30.                 it++;
  31.             }
  32.             it++;
  33.             if(it != st.end()) {
  34.                 res = min(res, *it - x);
  35.             }
  36.            
  37.         }
  38.         else {
  39.             cout << res << " ";
  40.         }
  41.     }
  42.    
  43.    
  44.    
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment