Cod sursa(job #1152216)
Utilizator | Data | 24 martie 2014 16:48:55 | |
---|---|---|---|
Problema | Zeap | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 3.35 kb |
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;
set <int> S, dif;
set <int>::iterator it, aux, j, h, q;
int main()
{
freopen( "zeap.in", "r", stdin );
freopen( "zeap.out", "w", stdout );
while( !feof( stdin ) ){
char line[15];
memset( line, 0, sizeof( line ) );
gets( line );
int l = strlen( line );
if( l > 0 ){
if( line[0] != 'M' ){
int x = 0;
for( int i = 2; i < l; ++i )
x = x * 10 + line[i] - 48;
it = S.find( x );
if( line[0] == 'I' ){
if( it == S.end() ){
S.insert( x );
it = S.find( x );
if( it != S.begin() ){
j = it;
--j;
dif.insert( (*it) - (*j) );
h = it;
++h;
if( h != S.end() ){
dif.insert( (*h) - (*it) );
q = dif.find( (*h) - (*j) );
if( q != dif.end() )
dif.erase( q );
}
}
else{
h = it;
++h;
if( h != S.end() )
dif.insert( (*h) - (*it) );
}
}
}
else if( line[0] == 'S' ){
if( it != S.end() ){
if( it != S.begin() ){
j = it;
--j;
q = dif.find( (*it) - (*j) );
if( q != dif.end() )
dif.erase( q );
h = it;
++h;
if( h != S.end() ){
q = dif.find( (*h) - (*it) );
if( q != dif.end() )
dif.erase( q );
dif.insert( (*h) - (*j) );
}
}
else{
h = it;
++h;
if( h != S.end() ){
q = dif.find( (*h) - (*it) );
if( q != dif.end() )
dif.erase( q );
}
}
S.erase( it );
}
else printf( "-1\n" );
}
else{
if( it != S.end() ) printf( "1\n" );
else printf( "0\n" );
}
}
else {
if( line[1] == 'A' ){
if( S.size() > 1 ){
it = S.end();
--it;
aux = S.begin();
printf( "%d\n", (*it) - (*aux) );
}
else printf( "-1\n" );
}
else{
if( S.size() > 1 ){
it = dif.begin();
printf( "%d\n", (*it) );
}
else printf( "-1\n" );
}
}
}
}
fclose( stdin );
fclose( stdout );
return 0;
}