Cod sursa(job #805358)

Utilizator mathboyDragos-Alin Rotaru mathboy Data 31 octombrie 2012 11:33:08
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <cstdio>
#include <vector>
#define VIT vector <int> :: iterator
const int mod = 666013;

using namespace std;

vector <int> G[mod+2];
int m, n;
void add_hash(int val) {
	m = val % mod;
	for(VIT it = G[m].begin(); it != G[m].end(); it++) 
		if(*it == val) return ;
	G[m].push_back(val);
}
void del_hash(int val) {
	m = val % mod;
	for(VIT it = G[m].begin(); it != G[m].end(); ++it)
		if(*it == val) {
			G[m].erase(it); return ;
		}
}
void find_hash(int val) {
	m = val % mod;
	for(VIT it = G[m].begin(); it != G[m].end(); ++it)
		if(*it == val) {
			printf("1\n"); return ;
		}
	printf("0\n");
}
int main() {
	
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	int t, x;
	for( scanf("%d\n", &n); n--; ) {
		scanf("%d %d\n", &t, &x);
		if(t == 1) add_hash(x);
		if(t == 2) del_hash(x);
		if(t == 3) find_hash(x);
	}
	
	return 0;
}