Cod sursa(job #773107)

Utilizator dspMihaiDespotovici Mihai dspMihai Data 1 august 2012 00:42:11
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define MOD 599110
using namespace std;
vector <unsigned long> v[MOD+5];
unsigned long N,i,crt,l,hash;
long ok;
int operatie;
int main ()
{
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	scanf("%d", &N);
	for (; N>0; N--)
	{
		scanf("%d %ld", &operatie, &crt); 
		if (operatie==1) 
		{
			hash=crt%MOD;
			ok=-1;
			l=v[hash].size();
			for (i=0; i<l && ok<0; i++) if (v[hash][i]==crt) ok=i;
			if (ok<0) v[hash].push_back(crt);
		}
		else if (operatie==2) 
		{
			hash=crt%MOD;
			ok=-1;
			l=v[hash].size();
			for (i=0; i<l && ok<0; i++) if (v[hash][i]==crt) ok=i;
			if (ok!=-1) v[hash].erase(v[hash].begin());
		}
		else if (operatie==3)
		{
			hash=crt%MOD;
			ok=-1;
			l=v[hash].size();
			for (i=0; i<l && ok<0; i++) if (v[hash][i]==crt) ok=i;
			if (ok!=-1) printf("1\n");
			else printf("0\n");
		}
	}


	fclose(stdin); fclose(stdout);
	return 0;
}