Cod sursa(job #1454149)

Utilizator GilgodRobert B Gilgod Data 25 iunie 2015 15:36:03
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.22 kb
#include <iostream>
#include <fstream>
#include <list>
#include <assert.h>

const int MOD = 666013;
const char IN[] = "hashuri.in", OUT[] = "hashuri.out";

using namespace std;

inline int get_key(int e) {
	return e % MOD;
}

list<int>	hashMap[MOD];
int			OP;

inline void map_add(int x) {
	int key = get_key(x);
	for (auto& it : hashMap[key]) {
		if (it == x) return;
	}
	hashMap[key].push_back(x);
}

inline void map_remove(int x) {
	int key = get_key(x);
	std::list<int>::iterator it;
	for (it = hashMap[key].begin(); it != hashMap[key].end(); ++it) {
		if (*it == x) break;
	}
	if (it == hashMap[key].end()) return;
	hashMap[key].erase(it);
}

inline int map_find(int x) {
	int key = get_key(x);
	for (auto& it : hashMap[key]) {
		if (it == x) return true;
	}
	return false;
}

inline void read_data() {
	assert(freopen(IN, "r", stdin));
	assert(scanf("%d", &OP));
	assert(freopen(OUT, "w", stdout));
	for (int i = 1; i <= OP; ++i) {
		int o, x;
		assert(scanf("%d %d", &o, &x));
		switch (o) {
		case 1: map_add(x); break;
		case 2: map_remove(x); break;
		case 3: printf("%d\n", map_find(x)); break;
		}
	}
	fclose(stdin);
	fclose(stdout);
}

int main() {
	read_data();
	return 0;
}