Cod sursa(job #641950)

Utilizator mr.johnFMI - Laceanu Ionut-Adrian mr.john Data 30 noiembrie 2011 00:32:27
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <stdio.h>
#include <vector>

using namespace std;
#define MOD 100003
int n;
vector<int> hash[MOD];


inline vector<int>::iterator gaseste(int x){
	int ind=x%MOD;
	vector<int>::iterator it;
	for (it=hash[ind].begin(); it!=hash[ind].end(); it++)
		if (*it==x) return it;
	return hash[ind].end();
}

void insert(int x){
	int ind=x%MOD;
	if (gaseste(x)==hash[ind].end())
		hash[ind].push_back(x);
}

void sterge(int x){
	int ind=x%MOD;
	vector<int>::iterator it=gaseste(x);
	if (it!=hash[ind].end())
		hash[ind].erase(it);
}

int main(){
	int op,nr;
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d %d",&op,&nr);
		if (op==1) insert(nr);
		if (op==2) sterge(nr);
		if (op==3) printf("%d\n",gaseste(nr)==hash[nr].end()?0:1);
	}
	return 0;
}