Pagini recente » Cod sursa (job #14524) | Cod sursa (job #2337328) | Cod sursa (job #2124185) | Cod sursa (job #2595852) | Cod sursa (job #1013421)
#include <cstdio>
#include <cassert>
#include <vector>
using namespace std;
#define MOD 999983
vector < int > h[MOD];
inline bool find( int x ) {
int equiv = x % MOD;
vector < int > :: iterator it = h[equiv].begin();
while ( it != h[equiv].end() && *it != x )
++it;
return ( it != h[equiv].end() && *it == x );
}
inline void insert( int x ) {
if ( !find( x ) )
h[x % MOD].push_back( x );
}
inline void erase( int x ) {
int equiv = x % MOD;
vector < int > :: iterator it = h[equiv].begin();
while ( it != h[equiv].end() && *it != x )
++it;
if ( it != h[equiv].end() && *it == x )
h[equiv].erase( it );
}
int main() {
FILE *fin, *fout;
fin = fopen( "hashuri.in", "r" );
int q;
assert( fscanf( fin, "%d", &q ) == 1 );
fout = fopen( "hashuri.out", "w" );
while ( q ) {
int type, val;
assert( fscanf( fin, "%d%d", &type, &val ) == 2 );
if ( type == 1 )
insert( val );
else if ( type == 2 )
erase( val );
else
fprintf( fout, "%d\n", find( val ) ? 1 : 0 );
--q;
}
fclose( fin );
fclose( fout );
}