Pagini recente » Cod sursa (job #724034) | Cod sursa (job #697690) | Cod sursa (job #1975836) | Cod sursa (job #971700) | Cod sursa (job #1749994)
#include <cstdio>
#include <vector>
using namespace std;
#define MOD 100003
#define MOD_F2 20012
vector < int > v[ MOD + 10 ];
int key;
void add( int x);
void sterge( int x );
vector<int>::iterator cauta( int x );
int hash32shift(int key)
{
key = ~key + (key << 15); // key = (key << 15) - key - 1;
key = key ^ (key >> 12);
key = key + (key << 2);
key = key ^ (key >> 4);
key = key * 2057; // key = (key + (key << 3)) + (key << 11);
key = key ^ (key >> 16);
return key % MOD;
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int n, i, j, x, y;
scanf("%d",&n);
while( n-- ){
scanf("%d%d",&x,&y);
key = hash32shift( y );
if( x == 1 ) add( y );
else if( x == 2 ) sterge( y );
else printf( "%d\n",cauta( y ) != v[ key ].end() );
}
return 0;
}
vector<int>::iterator cauta( int x )
{
vector<int>::iterator it;
for( it = v[ key ].begin(); it != v[ key ].end(); ++it)
if ( *it == x )
return it;
return v[ key ].end();
}
void add( int x )
{
if( cauta( x ) == v[ key ].end())
v[ key ].push_back( x );
}
void sterge( int x )
{
vector<int>::iterator it = cauta( x );
if( it != v[ key ].end() )
v[ key ].erase( it );
}