2020-10-13 12:15:32 +00:00
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
map<int, int> m;
|
2021-11-19 09:01:13 +00:00
|
|
|
int i, j, n, x, y;
|
2020-10-13 12:15:32 +00:00
|
|
|
cin >> n;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
cin >> x >> y;
|
|
|
|
if (x == 1) {
|
|
|
|
if (m.count(y)) {
|
|
|
|
cout << "Already Exist" << endl;
|
2021-11-19 09:01:13 +00:00
|
|
|
} else {
|
2020-10-13 12:15:32 +00:00
|
|
|
m[y] = 1;
|
|
|
|
}
|
2021-11-19 09:01:13 +00:00
|
|
|
} else {
|
2020-10-13 12:15:32 +00:00
|
|
|
if (m.empty()) {
|
|
|
|
cout << "Empty" << endl;
|
2021-11-19 09:01:13 +00:00
|
|
|
} else if (m.count(y)) {
|
2020-10-13 12:15:32 +00:00
|
|
|
m.erase(y);
|
|
|
|
cout << y << endl;
|
2021-11-19 09:01:13 +00:00
|
|
|
} else {
|
|
|
|
m[y] = 1;
|
|
|
|
map<int, int>::iterator it = m.find(y);
|
2020-10-13 12:15:32 +00:00
|
|
|
map<int, int>::iterator it2 = it;
|
|
|
|
it++;
|
|
|
|
if (it2 == m.begin()) {
|
|
|
|
cout << it->first << endl;
|
|
|
|
m.erase(it);
|
2021-11-19 09:01:13 +00:00
|
|
|
} else if (it == m.end()) {
|
2020-10-13 12:15:32 +00:00
|
|
|
cout << (--it2)->first << endl;
|
|
|
|
m.erase(it2);
|
2021-11-19 09:01:13 +00:00
|
|
|
} else if (y - (--it2)->first > it->first - y) {
|
2020-10-13 12:15:32 +00:00
|
|
|
cout << it->first << endl;
|
|
|
|
m.erase(it);
|
2021-11-19 09:01:13 +00:00
|
|
|
} else {
|
2020-10-13 12:15:32 +00:00
|
|
|
cout << it2->first << endl;
|
|
|
|
m.erase(it2);
|
|
|
|
}
|
|
|
|
m.erase(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|