Cod sursa(job #1032630)

Utilizator danny794Dan Danaila danny794 Data 15 noiembrie 2013 20:12:20
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <cstdio>
#include <vector>

#define NMAX 100000

using namespace std;

vector<int> set[NMAX];
int N;

void read(){
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
}

inline int hashCode(int x){
	return x % NMAX;
}

inline int isIn(int x, int hash){
	vector<int> :: iterator it;
	for (it = set[hash].begin(); it != set[hash].end(); it++)
		if(*it == x){
			return it - set[hash].begin();
		}
	return -1;
}

inline void add(int x){
	int hash = hashCode(x);
	int pos = isIn(x, hash);
	if (pos < 0){
		set[hash].push_back(x);
	}
}

inline void remove(int x){
	int hash = hashCode(x);
	int pos = isIn(x, hash);
	if (pos >= 0){
		set[hash].erase(set[hash].begin() + pos);
	}
}

void apply(int op, int x){
	switch(op){
	case(1): add(x); break;
	case(2): remove(x); break;
	case(3): if (isIn(x, hashCode(x)) < 0)
				printf("0\n");
			else
				printf("1\n");
			break;
	}
}

int main() {
	read();
	int op, x;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++){
		scanf("%d %d", &op, &x);
		apply(op, x);
	}
	return 0;
}