Cod sursa(job #2276769)

Utilizator cezar.plescaCezar Plesca cezar.plesca Data 5 noiembrie 2018 12:19:32
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 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;

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

	return 0;
}