Advertisement
Josif_tepe

Untitled

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