Pagini recente » Cod sursa (job #359251) | Cod sursa (job #2237850) | Cod sursa (job #346487) | Cod sursa (job #985020) | Cod sursa (job #985027)
Cod sursa(job #985027)
#include <iostream>
#include <string>
#include <fstream>
#include <set>
#define DN 300005
using namespace std;
ifstream f("zeap.in");
ofstream g("zeap.out");
int p=0;
string s;
multiset < int > st,min_dif;
multiset < int >::iterator it,it2;
int main()
{
st.insert(0);
st.insert(1<<30);
it=st.begin();
while(!f.eof())
{
int x;
f>>s;
//cout<<s<<endl;
/*cout<<" Numere : \n";
for( it = st.begin();it!=st.end();++it)
cout<<*it<<" ";
cout<<"\n Dif :\n";
for( it = min_dif.begin();it!=min_dif.end();++it)
cout<<*it<<" ";
cout<<endl;*/
if(s[0]=='I')
{
f>>x;
if(st.size()==2)
st.insert(x);
else
{
it=st.lower_bound(x);
it2=it;
--it2;
if( *it2 != 0 && *it != (1<<30) )
min_dif.erase ( *it - *it2 );
if( *it != (1<<30))
min_dif.insert( *it - x );
if(*it2 != 0 )
min_dif.insert( x - *it2 );
st.insert(x);
}
}
if(s[0]=='S')
{
f>>x;
it=st.lower_bound(x);
if( *it != x )
{
g<<-1<<"\n";
continue;
}
it2=it;
--it2;
++it;
if( *it != (1<<30))
min_dif.erase( *it - x );
if(*it2 != 0 )
min_dif.erase( x - *it2 );
st.erase(x);
if( *it2 != 0 && *it != (1<<30) )
min_dif.insert ( *it - *it2 );
}
if(s[0]=='M' && s[1]=='A')
{
it=st.begin();
++it;
it2=st.end();
--it2; --it2;
if(st.size()>=4)
g<<( *it2- *it )<<"\n";
else
g<<"-1"<<"\n";
}
else
if(s[0]=='M' && s[1]=='I')
{
if(min_dif.size())
g<< *min_dif.begin() <<"\n";
else
g<<"-1"<<"\n";
}
if(s[0]=='C')
{
f>>x;
it=st.lower_bound(x);
if(*it == x)
g<<1<<"\n";
else
g<<0<<"\n";
}
getline(f,s);
}
return 0;
}