Cod sursa(job #731248)

Utilizator gabrielvGabriel Vanca gabrielv Data 7 aprilie 2012 19:55:43
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
using namespace std;
#include<cstdio>
#include<vector>
#define MAX 600043
vector <int> G[MAX];
int search(int x, int unsigned i, int unsigned n, int mod)
{
	for(;i<n;i++)
		if(G[mod][i]==x)
			return i;
	return -1;
}
void insert(int x)
{
	int mod=x%MAX;
	if(search(x,0,G[mod].size(),mod)==-1)
		G[mod].push_back(x);
}
void remove(int x)
{
	int mod=x%MAX;
	if(search(x,0,G[mod].size(),mod)!=-1)
		G[mod].erase(G[mod].begin()+search(x,0,G[mod].size(),mod));
}
int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	int n,op,x;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d",&op,&x);
		switch(op)
		{
			case 1: { insert(x); break;}
			case 2: { remove(x); break;}
			case 3: { if(search(x,0,G[x%MAX].size(),x%MAX)!=-1) printf("1\n"); else printf ("0\n"); break;}
		}
	}
	return 0;
}