Pagini recente » Cod sursa (job #1575244) | Cod sursa (job #1074066) | Cod sursa (job #1120736) | Cod sursa (job #233693) | Cod sursa (job #1148670)
#include<cstdio>
#include<set>
using namespace std;
int x,poz;
char T[20],*p;
set<int> S,D;
set<int>::iterator it,it2,it3;
int main()
{
freopen("zeap.in","r",stdin);
freopen("zeap.out","w",stdout);
for(;fgets(T,20,stdin);)
{
if(T[0]=='I')
{
p=T+2; x=0;
while(*p>='0' && *p<='9') x=x*10+*p-'0',p++;
it=S.find(x);
if(it==S.end())
{
S.insert(x); it=S.find(x);
if(S.size()>1)
{
it3=it; it3++;
it2=it; it2--;
if(it==S.begin()) D.insert(*it3-*it);
else if(it3==S.end()) D.insert(*it-*it2);
else
{
D.erase(D.find(*it3-*it2));
D.insert(*it-*it2);
D.insert(*it3-*it);
}
}
}
}
else if(T[0]=='S')
{
p=T+2; x=0;
while(*p>='0' && *p<='9') x=x*10+*p-'0',p++;
it=S.find(x);
if(it==S.end()) printf("-1\n");
else
{
if(S.size()>1)
{
it3=it; it3++;
it2=it; it2--;
if(it==S.begin()) D.erase(D.find(*it3-*it));
else if(it3==S.end()) D.erase(D.find(*it-*it2));
else
{
D.insert(*it3-*it2);
D.erase(D.find(*it-*it2));
D.erase(D.find(*it3-*it));
}
}
S.erase(it);
}
}
else if(T[0]=='C')
{
p=T+2; x=0;
while(*p>='0' && *p<='9') x=x*10+*p-'0',p++;
it=S.find(x);
if(it==S.end()) printf("0\n"); else printf("1\n");
}
else if(T[1]=='A')
{
if(S.size()<2) printf("-1\n");
else
{
it3=S.end(); it3--;
it2=S.begin();
printf("%d\n",*it3-*it2);
}
}
else
{
if(S.size()<2) printf("-1\n");
else printf("%d\n",*D.begin());
}
}
return 0;
}