Cod sursa(job #1053840)

Utilizator andy1496Casu-Pop Andrei andy1496 Data 12 decembrie 2013 23:20:04
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>
#include <vector>
using namespace std;
#define mod 666013
int n;
vector <int> list[mod];

int find (int val) {
	
	int i, ind = val % mod;
	for (i=0; i<list[ind].size(); i++) {
		if (list[ind][i]==val) {
			return i;
		}
	}
	return -1;
	
}

void insert (int val) {
	int ind=val%mod;
	if (find(val)==-1) {
		list[ind].push_back(val);
	}
}

void erase (int val) {
	int poz,ind = val%mod;
	poz=find(val);
	if (poz!=-1) {
		list[ind].erase(list[ind].begin()+poz);
	}
}

int main () {
	
	int t,val,j;
	freopen ("hashuri.in", "r", stdin);
	freopen ("hashuri.out", "w", stdout);
	
	scanf ("%d", &n);
	for (j=1; j<=n; j++) {
		
		scanf ("%d %d", &t, &val);
		
		if (t==1) insert(val);
		if (t==2) erase(val);
		if (t==3) {
			if (find(val)==-1) printf("%d\n", 0);
			else printf ("%d\n", 1);
		}
	}
	
}