Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- using namespace std;
- typedef long long ll;
- const ll INF = 2e18;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int k;
- cin >> k;
- ll res = INF;
- set<ll> st;
- for(int i = 0; i < k; 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 << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment