Cod sursa(job #1459119)

Utilizator theprdvtheprdv theprdv Data 9 iulie 2015 10:25:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <stdio.h>
#include <vector>
#define MOD 666013
#define list (x % MOD)

using namespace std;

int N;
vector<int> G[MOD];

inline decltype(G[0].begin()) find_val(int x){
	decltype(G[0].begin()) it;
	
	for (it = G[list].begin(); it != G[list].end(); ++it)
		if (*it == x) return it;
	return it;
}

inline void insert_val(int x){
	if (find_val(x) == G[list].end())
		G[list].push_back(x);
}

inline void erase_val(int x){
	decltype(G[0].begin()) it = find_val(x);

	if (it != G[list].end())
		G[list].erase(it);
}

int main()
{
	int type, x;

	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	
	for (scanf("%d", &N); N; --N){
		scanf("%d %d", &type, &x);
		switch (type){
		case 1: 
			insert_val(x);
			break;
		case 2:
			erase_val(x);
			break;
		case 3:
			printf("%d\n", find_val(x) != G[x % MOD].end());
			break;
		}
	}

	return 0;
}