Advertisement
Josif_tepe

Untitled

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