Cod sursa(job #251126)

Utilizator alexeiIacob Radu alexei Data 1 februarie 2009 22:38:55
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include<stdio.h>
#include<vector>
#define MOD 666013
using namespace std;

vector< int >H[MOD];

inline bool find( const int val )
{
	int pos=val%MOD;
	vector< int >::iterator it;
	
	for(it=H[pos].begin(); it!=H[pos].end(); ++it)
		if( *it==val )
			return 1;
	return 0;
}

inline void erase( const int val )
{
	int pos=val%MOD;

	vector< int >::iterator it;
	for(it=H[pos].begin(); it!=H[pos].end(); ++it)
		if( *it==val )
		{
			H[pos].erase(it);
			break;
		}
	
}

inline void insert( const int val )
{
	int pos=val%MOD;
	
	if( !find( val ) )
		H[ pos ].push_back( val );
}

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	int T;
	scanf("%d",&T);
	
	int a1,a2;

	while( T-- )
	{
		scanf("%d%d",&a1,&a2);
		if( a1==1 )
			insert( a2 );
		if( a1==2 )
			erase( a2 );
		if( a1==3 )
			printf("%d\n",find(a2));
	}

	return 0;
}//foarte elegant :)