Pagini recente » Cod sursa (job #810622) | Cod sursa (job #1329962)
#include <fstream>
#include <set>
using namespace std;
ifstream f("zeap.in");
ofstream g("zeap.out");
typedef pair<set<int>::iterator,bool> pib;
const int INF = (1LL<<31)-1;
char c;
int x,a,b;
set<int> s;
multiset<int> ms;
set<int>::iterator it;
pib p;
int main()
{
s.insert(0);
s.insert(INF);
while( f >> c ){
if( c == 'I' ){
f >> x;
p = s.insert(x);
if( p.second ){
it = p.first;
--it;
a = *it;
++it; ++it;
b = *it;
if( a > 0 ) ms.insert(x-a);
if( b < INF) ms.insert(b-x);
if( a > 0 && b < INF ) ms.erase( ms.find(b-a) );
}
continue;
}
if( c == 'S' ){
f >> x;
it = s.find(x);
if( it != s.end() ){
--it;
a = *it;
++it; ++it;
b = *it;
--it;
if( a > 0 ) ms.erase( ms.find( x - a ) );
if( b < INF) ms.erase( ms.find( b - x ) );
if( a > 0 && b < INF ) ms.insert(b - a );
s.erase(it);
}
else g <<"-1\n";
continue;
}
if( c == 'C' ){
f >> x;
g << ( s.find(x) != s.end() ) << '\n';
continue;
}
f >> c; f >> c;
if( s.size() < 4 ){
g << "-1\n";
continue;
}
if( c == 'X'){
it = s.end();
--it; --it;
a = *it;
it = s.begin();
++it;
b = *it;
g << a - b << '\n';
continue;
}
else{
g << *ms.begin() << '\n';
continue;
}
}
return 0;
}