Cod sursa(job #432182)

Utilizator NemultumituMatei Ionita Nemultumitu Data 1 aprilie 2010 22:29:05
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <cstdio>
#include <vector>
#define q 4000001
#define p 4000003
#define r 1000007
using namespace std;
int n;
vector <pair <int,int> > hash[p];

void push(int x)
{
	int i;
	for (i=0;i<hash[x%p].size()&&hash[x%p][i].first!=x%r&&hash[x%p][i].second!=x%q;++i);
	if (i==hash[x%p].size())
		hash[x%p].push_back(make_pair(x%r,x%q));
}

void pop(int x)
{
	int i;
	for (i=0;i<hash[x%p].size()&&hash[x%p][i].first!=x%r&&hash[x%p][i].second!=x%q;++i);
	if (i!=hash[x%p].size())
	{
		hash[x%p][i].first=-1;
		hash[x%p][i].second=-1;
	}
}

void query(int x)
{
	int i;
	for (i=0;i<hash[x%p].size()&&hash[x%p][i].first!=x%r&&hash[x%p][i].second!=x%q;++i);
	if (i!=hash[x%p].size())
		printf("%d\n",1);
	else
		printf("%d\n",0);
}

int main()
{
	freopen ("hashuri.in","r",stdin);
	freopen ("hashuri.out","w",stdout);
	scanf("%d",&n);
	int x,y;
	while (n--)
	{
		scanf("%d%d",&y,&x);
		if (y==1)
			push(x);
		if (y==2)
			pop(x);
		if (y==3)
			query(x);
	}
	return 0;
}