Untitled
unknown
c_cpp
10 months ago
677 B
3
Indexable
#include <iostream> #include <set> using namespace std; set<int> s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while (n--) { int type, x; cin >> type >> x; if (type == 1) { if (s.find(x) != s.end()) s.erase(x); else s.insert(x); } else { if (s.size() < 2) cout << -1 << endl; else { set<int>::iterator rb = s.lower_bound(x+1); set<int>::iterator lb = prev(rb); cout << ((rb == s.end() || rb == s.begin()) ? -1 : *rb - *lb) << endl; } } } }
Editor is loading...
Leave a Comment