Pagini recente » Cod sursa (job #1972737) | Cod sursa (job #1342203) | Cod sursa (job #630457) | Cod sursa (job #1942432) | Cod sursa (job #2897756)
#include <bits/stdc++.h>
using namespace std;
ifstream f("zeap.in");
ofstream g("zeap.out");
#define cin f
#define cout g
set < int > zeap;
priority_queue < int > dif, lazy;
int main()
{
string s;
while(cin >> s)
{
if(s[0] == 'I')
{
int x; cin >> x;
if(zeap.find(x) == zeap.end())
{
zeap.insert(x);
auto find = zeap.find(x);
auto before = find, after = find;
before --, after ++;
if(find != zeap.begin())
dif.push(- abs(*before - *find));
if(after != zeap.end())
dif.push(- abs(*find - *after));
if(find != zeap.begin() and after != zeap.end())
lazy.push(- abs(*before - *after));
}
}
else if(s[0] == 'S')
{
int x; cin >> x;
if(zeap.find(x) != zeap.end())
{
auto find = zeap.find(x);
auto before = find, after = find;
before --, after ++;
if(find != zeap.begin())
lazy.push(- abs(*before - *find));
if(after != zeap.end())
lazy.push(- abs(*find - *after));
if(find != zeap.begin() and after != zeap.end())
dif.push(- abs(*before - *after));
zeap.erase(x);
}
else
cout<<-1<<'\n';
}
else if(s[0] == 'C')
{
int x; cin >> x;
if(zeap.find(x) != zeap.end())
cout<<1<<'\n';
else
cout<<0<<'\n';
}
else if(s[1] == 'A')
{
if(zeap.size() > 1)
cout<<*(-- zeap.end()) - *(zeap.begin())<<'\n';
else
cout<<-1<<'\n';
}
else
{
if(zeap.size() > 1)
{
while(! lazy.empty() and dif.top() == lazy.top())
{
dif.pop();
lazy.pop();
}
cout<<- dif.top()<<'\n';
}
else
cout<<-1<<'\n';
}
}
return 0;
}