Cod sursa(job #795881)

Utilizator radustn92Radu Stancu radustn92 Data 9 octombrie 2012 20:08:33
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <stdio.h>
#include <vector>
#define MOD (1<<19)
#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)
		{
			if (i<A[rest].size()-1)
				A[rest][i]=A[rest][A[rest].size()-1];
			A[rest].erase(A[rest].end()-1);
			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;
}