Cod sursa(job #795882)

Utilizator radustn92Radu Stancu radustn92 Data 9 octombrie 2012 20:09:54
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <stdio.h>
#include <vector>
#define MOD (1<<18)
#define pb push_back
using namespace std;
int n;
vector <int> A[MOD];
inline int find(int rest,int val)
{
	int i,x;
	for (i=0; i<A[rest].size(); i++)
	{
		x=A[rest][i];
		if (x==val)
			return 1;
	}
	return 0;
}
void del(int rest,int val)
{
	int i,x;
	for (i=0; i<A[rest].size(); i++)
	{
		x=A[rest][i];
		if (x==val)
		{
			A[rest][i]=0;
			return ;
		}
	}
}
void add(int rest,int val)
{
	A[rest].pb(val);
}
int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	scanf("%d",&n);
	int i,tip,x,rest;
	for (i=1; i<=n; i++)
	{
		scanf("%d%d",&tip,&x);
		rest= x & (MOD-1);
		if (tip==1 && !find(rest,x))
			add(rest,x);
		if (tip==2 && find(rest,x))
			del(rest,x);
		if (tip==3)
			printf("%d\n",find(rest,x));
	}
	return 0;
}