Cod sursa(job #629323)

Utilizator stay_awake77Cangea Catalina stay_awake77 Data 3 noiembrie 2011 10:16:19
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <fstream>
#include <vector>
#include <algorithm>

#define MOD 666013
#define pb push_back

using namespace std;

vector< int > H[MOD];
int op, x, N;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

inline void Add( int pos, int val )
{
	for( vector< int >::iterator it = H[ pos ].begin(); it != H[ pos ].end(); ++it )
		if( *it == val ) return;
	
	H[ pos ].pb( val );
}

inline void Remove( int pos, int val )
{
	for( vector< int >::iterator it = H[ pos ].begin(); it != H[ pos ].end(); ++it )
		if( *it == val )
		{
			swap( *it, *( H[ pos ].end() - 1 ) );
			H[ pos ].pop_back();
			return;
		}
}

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

int main()
{
	in >> N;
	
	while( N-- )
	{
		in >> op >> x;
		switch( op )
		{
			case 1:
				Add( x%MOD, x );
				break;
			case 2:
				Remove( x%MOD, x );
				break;
			case 3:
				out << Q( x%MOD, x ) << '\n';
				break;
		}
	}
	
	return 0;
}