Pagini recente » Cod sursa (job #626360) | Cod sursa (job #2474197) | Cod sursa (job #717172) | Cod sursa (job #2947561) | Cod sursa (job #1751054)
#include <cstdio>
#include <vector>
using namespace std;
#define NMAX 104729
vector < int > v[ NMAX + 1 ];
vector < int > g[ NMAX + 1 ];
int firstKey( int x );
int secondKey( int x );
void add( int x );
void sterge( int x );
bool cauta( int x );
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int n, m, i, j, s, t, d, x, y;
scanf("%d",&n);
while( n-- ){
scanf("%d%d",&x,&y);
if( x == 1 ) add( y );
if( x == 2 ) sterge( y );
if( x == 3 ) printf("%d\n",cauta( y ));
}
return 0;
}
void add( int x ){
if( cauta( x ) ) return ;
int key1 = firstKey( x );
int key2 = secondKey( x );
if( v[ key1 ].size() < g[ key2 ].size() ) v[ key1 ].push_back( x );
else g[ key2 ].push_back( x );
}
void sterge( int x ){
int key1 = firstKey( x );
int key2 = secondKey( x );
int j;
vector < int > :: iterator i;
for( i = v[ key1 ].begin(); i != v[ key1 ].end(); ++i ){
if( *i == x ){
v[ key1 ].erase( i );
return ;
}
}
for( i = g[ key2 ].begin(); i != g[ key2 ].end(); ++i ){
if( *i ){
g[ key2 ].erase( i );
return ;
}
}
}
bool cauta( int x ){
int key1 = firstKey( x );
int key2 = secondKey( x );
int i, j;
for( i = 0; i < v[ key1 ].size(); ++i )
if( v[ key1 ][ i ] == x ) return 1;
for( i = 0; i < g[ key2 ].size(); ++i )
if( g[ key2 ][ i ] == x ) return 1;
return 0;
}
int firstKey( int x ){ return ( x % NMAX ); }
int secondKey( int x ){ return ( x % NMAX + 100003 - x % 100003 ) % NMAX; }