Cod sursa(job #543756)

Utilizator avram_florinavram florin constantin avram_florin Data 28 februarie 2011 16:08:05
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include<fstream>
#include<vector>
#include<cstdio>
#define Mod 666013

using namespace std;

int n;
vector<int> V[Mod];

vector<int>::iterator find(int x)
{
	int key = x%Mod;
	vector<int>::iterator it;
	for( it = V[key].begin() ; it != V[key].end() ; ++it )
		if( *it == x )
			return it;
	return V[key].end();
}

void insert(int x)
{
	int key = x%Mod;
	if( find(x) == V[key].end() )
		V[key].push_back(x);
}

void erase(int x)
{
	int key = x%Mod;
	vector<int>::iterator it;
	it = find(x);
	if( it != V[key].end() )
		V[key].erase(it);
}

int main(void)
{
	freopen("hashuri.in" , "r" , stdin);
	freopen("hashuri.out" , "w" , stdout);
	scanf("%d" , &n);
	int i,tip,x;
	for( i = 1 ; i <= n ; i++ )
		{
			scanf("%d%d" , &tip , &x );
			if( tip == 1 )
				insert(x);
				else
				if( tip == 2 )
					erase(x);
					else
					printf("%d\n" , find(x) != V[x%Mod].end() );
		}
	return 0;
}