Cod sursa(job #336529)

Utilizator rumburakrumburak rumburak Data 31 iulie 2009 18:25:40
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include<cstdio>
#include<vector>

using namespace std;

const int k = 999983;

vector<int> v[k];

void adauga(int x)
{
	int r=x%k;
	for(vector<int>::iterator it=v[r].begin() ; it!=v[r].end() ; ++it)
		if(*it==x)
			return;
	v[r].push_back(x);
}

void sterge(int x)
{
	int r=x%k;
	for(vector<int>::iterator it=v[r].begin() ; it!=v[r].end() ; ++it)
		if(*it==x)
		{
			v[r].erase(it);
			return;
		}
}

int exista(int x)
{
	int r=x%k;
	for(vector<int>::iterator it=v[r].begin() ; it!=v[r].end() ; ++it)
		if(*it==x)
			return 1;
	return 0;
}

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	int i,n,op,x;
	scanf("%d",&n);
	for(i=0;i<n;++i)
	{
		scanf("%d%d",&op,&x);
		if(op==1)
			adauga(x);
		if(op==2)
			sterge(x);
		if(op==3)
			printf("%d\n",exista(x));
	}
	return 0;
}