Cod sursa(job #642900)

Utilizator mihaibogdan10Mihai Bogdan mihaibogdan10 Data 2 decembrie 2011 15:26:04
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
#include<cstdio>
#include<vector>
#define MOD 666013
using namespace std;

char buff[8192];
int poz, n, ind;
vector <int> h[MOD];

void Read(int &nr){
	nr = 0;
	while (buff[poz] < '0' || buff[poz] > '9')
		if (++poz == 8192) {fread(buff, 1, 8192, stdin); poz = 0;}
	while (buff[poz] >= '0' && buff[poz] <= '9'){
		nr = nr * 10 + (buff[poz] - '0');
		if (++poz == 8192) {fread(buff, 1, 8192, stdin); poz = 0;}
	}
}

vector<int> :: iterator Cauta(int x){
	vector<int> :: iterator it;
	for (it = h[ind].begin(); it != h[ind].end(); it++)
		if (*it == x) return it;
	return h[ind].end();
}

void Insereaza(int x){
	if (Cauta(x) == h[ind].end()) h[ind].push_back(x);
}

void Sterge(int x){
	vector<int> :: iterator it = Cauta(x);
	if (it != h[ind].end()) h[ind].erase(it);
}

int main(){
	freopen ("hashuri.in", "r", stdin), freopen("hashuri.out", "w", stdout);
	
	int i, n, x, op;
	Read(n);
	for (i = 0; i < n; i++){
		Read(op), Read(x);
		ind  = x % MOD;
		switch (op){
			case 1: {Insereaza(x); break;}
			case 2: {Sterge(x); break;}
		case 3: printf("%d\n", Cauta(x) == h[ind].end()? 0 : 1);
		}
	}
	return 0;
}