Cod sursa(job #626491)

Utilizator zeeboBuzatu Vlad zeebo Data 27 octombrie 2011 12:14:35
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <stdio.h>
#include <vector>
#define M 666013
#define pb push_back
using namespace std;
int n,x,q;
vector <int> v[M];
void insert (vector <int> v[M], int x)
{
	int poz=x%M;
	v[poz].pb(x);
}
void erase (vector <int> v[M], int x)
{
	int poz=x%M;
	int len=v[poz].size();
	for (int i=0;i<len;i++)
		if (v[poz][i]==x)
		{
			v[poz].erase(v[poz].begin()+i);
			return;
		}
}
bool find (vector <int> v[M], int x)
{
	int poz=x%M;
	int len=v[poz].size();
	for (int i=0;i<len;i++)
		if (v[poz][i]==x) return true;
return false;
}
int main()
{
freopen ("hashuri.in","r",stdin);
freopen ("hashuri.out","w",stdout);

	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&q,&x);
		if (q==1) insert(v, x); 
		if (q==2) if (find(v,x)) erase(v,x);
		if (q==3) if (find(v,x)) printf("1\n");
				     else printf("0\n");
	}
return 0;
}