Cod sursa(job #2276778)

Utilizator cezar.plescaCezar Plesca cezar.plesca Data 5 noiembrie 2018 12:30:02
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <stdio.h>
#include <set>
#include <vector>

#include <fstream>
#include <algorithm>

using namespace std;
 
int N;

#define PRIME 666013

vector<int> hashtab[PRIME];

int main()
{
	//ifstream input("hashuri.in");
	//ofstream output("hashuri.out");

	freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

	int i, tip, x;
 
	//input >> N;
	scanf("%d", &N);

	unsigned int slot;	
	vector<int>::iterator it;

	for (i = 1; i <= N; i++) 
	{
		//input >> tip >> x;
		scanf("%d %d", &tip, &x);

		slot=x%PRIME;

		for (it = hashtab[slot].begin(); it != hashtab[slot].end(); ++it){
			if(*it==x)
				break;
		}

		switch(tip){
			case 1:
				if(it==hashtab[slot].end())
					hashtab[slot].push_back(x);
				break;
			case 2:
				if(it!=hashtab[slot].end())		
					hashtab[slot].erase(it);
				break;
			case 3:
				if(it!=hashtab[slot].end())
					printf("1\n");
					//output << "1" << endl;
				else
					printf("0\n");
					//output << "0" << endl;
				break;
		}
	}
 
	//input.close();
	//output.close();

	return 0;
}