Cod sursa(job #238858)

Utilizator blasterzMircea Dima blasterz Data 3 ianuarie 2009 14:40:32
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
using namespace std;
#include <cstdio>
#include <vector>
#define dim 8192
#define maxh 666777

char ax[dim];
int pz;

inline void cit(int &x)
{
	x=0;
	while(ax[pz]<'0' || ax[pz]>'9')
		if(++pz==dim)fread(ax,1,dim,stdin),pz=0;
	
	while(ax[pz]>='0' && ax[pz]<='9')
	{
		x=x*10+ax[pz]-'0';
		if(++pz==dim)fread(ax,1,dim,stdin),pz=0;
	}
}

typedef vector<int> vi;
typedef vector<int>::iterator vit;


vi H[maxh];

inline int find(int v)
{
	int h=v%maxh;
	for(vit i=H[h].begin(); i!=H[h].end(); ++i)
		if(*i == v) return 1;
	return 0;
}

inline void insert(int v)
{
	if(find(v) == 1) return;
	H[v%maxh].push_back(v);
}

inline void sterge(int v)
{
	int h=v%maxh;
	vit it, i;
	for(i=H[h].begin(); i!=H[h].end(); )
		if( *i == v ) i=H[h].erase(i);
		else ++i;
}

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	int n;
	cit(n);
	int t, p;
	
	while(n--)
	{
		cit(t);cit(p);
		
		if(t == 1) insert(p);
		if(t == 2) sterge(p);
		if(t == 3) printf("%d\n", find(p));
		
	}
	
	return 0;
}