Cod sursa(job #2276773)

Utilizator cezar.plescaCezar Plesca cezar.plesca Data 5 noiembrie 2018 12:24:37
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 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");
	int i, tip, x;
 
	input >> N;
	unsigned int slot;	
	vector<int>::iterator it;

	for (i = 1; i <= N; i++) 
	{
		input >> 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())
					output << "1" << endl;
				else
					output << "0" << endl;
				break;
		}
	}
 
	input.close();
	output.close();

	return 0;
}