Pagini recente » Cod sursa (job #2111481) | Cod sursa (job #3004324) | Cod sursa (job #1468586) | Cod sursa (job #714) | Cod sursa (job #2545082)
#include <bits/stdc++.h>
using namespace std;
ifstream fi("zeap.in");
ofstream fo("zeap.out");
const int INF = 1000000001;
char A[100];
set <int> S;
multiset <int> D;
int main()
{
S.insert(-INF);
S.insert(INF);
D.insert(2 * INF);
while (fi >> A + 1) {
if (A[1] == 'I') {
int x;
fi >> x;
auto it = S.upper_bound(x);
it--;
if (*it != x) {
it++;
int prev, nxt;
nxt = *it;
it--;
prev = *it;
auto it2 = D.upper_bound(nxt - prev);
it2--;
D.erase(it2);
S.insert(x);
D.insert(nxt - x);
D.insert(x - prev);
}
}
else if (A[1] == 'S') {
int x;
fi >> x;
auto it = S.upper_bound(x);
it--;
if (*it == x) {
int prev, nxt;
it++;
nxt = *it;
it--;
it--;
prev = *it;
it++;
S.erase(it);
auto it2 = D.upper_bound(nxt - x);
it2--;
D.erase(it2);
it2 = D.upper_bound(x - prev);
it2--;
D.erase(it2);
D.insert(nxt - prev);
}
else {
fo << -1 << "\n";
}
}
else if (A[1] == 'C') {
int x;
fi >> x;
auto it = S.upper_bound(x);
it--;
if (*it == x) {
fo << 1 << "\n";
}
else {
fo << 0 << "\n";
}
}
else if (A[1]=='M' && A[2] == 'A') {
if (S.size() < 4)
fo << -1 << "\n";
else {
int rez = 0;
auto it = S.end();
it--;
it--;
rez = *it;
it = S.begin();
it++;
rez -= (*it);
fo << rez << "\n";
}
}
else if (A[1] == 'M' && A[2] == 'I') {
if (S.size() < 4)
fo << -1 << "\n";
else {
auto it = D.begin();
fo << (*it) << "\n";
}
}
}
return 0;
}