Cod sursa(job #1040916)

Utilizator razvan2006razvan brezulianu razvan2006 Data 25 noiembrie 2013 09:34:42
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include<stdio.h>
#include<vector>
#define PRIM 666013

using namespace std;

vector<long> hash[PRIM];
long n, a[101][101];

inline vector<long>::iterator find_value(long x) {
	long hValue = x % PRIM;
	vector<long>::iterator it;
	
	for(it = hash[hValue].begin(); it != hash[hValue].end(); ++it) 
		if(*it == x)
			return it;
	
	return hash[hValue].end();
}

inline void insert_value(long x) {
	long hValue = x % PRIM;
	
	if(find_value(x) == hash[hValue].end())
		hash[hValue].push_back(x);
}

inline void erase_value(long x) {
	long hValue = x % PRIM;
	vector<long>::iterator it = find_value(x);
	
	if(it != hash[hValue].end())
		hash[hValue].erase(it);
}

int main() {
	freopen("hashuri.in", "rt", stdin);
	freopen("hashuri.out", "wt", stdout);
	
	scanf("%ld", &n);
	
	long x, op;
	for(int i = 0; i < n; i++) {
		scanf("%ld %ld", &op, &x);
		
		if(op == 1) {
			insert_value(x);
			continue;
		}
		if(op == 2) {
			erase_value(x);
			continue;
		}
		printf("%d\n", find_value(x) != hash[x % PRIM].end());
	}
	
	return 0;
}