Cod sursa(job #649039)

Utilizator the_snyper06FMI - ALexandru Mihai the_snyper06 Data 15 decembrie 2011 02:44:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include<cstdio>
#include<vector>
#define SIZE 719671

using namespace std;
int n, indice;
vector <int> L[SIZE];

int Cauta(int x) {	
	for(int i = 0; i < (int) L[indice].size(); i++)
		if(L[indice][i] == x) return i;
	
	return L[indice].size();
}

void Insert(int x) { if(Cauta(x) == (int)L[indice].size()) L[indice].push_back(x); }
void Delete(int x) { int i = Cauta(x);	if(i != (int)L[indice].size()) L[indice].erase(L[indice].begin() + i); }

int main() {
	int i, op, x;
	
	freopen("hashuri.in", "r", stdin), freopen("hashuri.out", "w", stdout);
	scanf("%d", &n);
	for(i = 1; i <= n; i++) {
		scanf("%d %d", &op, &x);
		indice = x % SIZE;
		switch(op) {
			case 1: Insert(x); break;
			case 2: Delete(x); break;
			case 3: printf("%d\n", Cauta(x) != (int)L[indice].size() ); break;
		}
	}
	
	return 0;
}