Cod sursa(job #1314500)

Utilizator space.foldingAdrian Soucup space.folding Data 11 ianuarie 2015 22:14:07
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.33 kb
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <utility>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <sstream>
#include <deque>
#include <bitset>
#include <complex>
#include <functional>
#include <memory>
#include <numeric>

using namespace std;

#define x first
#define y second

enum {
	MAX = 2000001,
};

int table[MAX], PMAX = 1999993;

int hashv(int v) {
	return ((long long)v * v + v + 1) % PMAX;
}

void add(int val) {
	int h = hashv(val);
	while(table[h]) h++;
	table[h] = val;
}

bool is(int val) {
	int h = hashv(val);
	while(table[h] && table[h] != val) h++;

	if(!table[h])
		return false;
	return true;
}

void del(int val) {
	int h = hashv(val);	
	while(table[h] && table[h] != val) h++;
	if(table[h]) table[h] = -1;	
}

int main () {
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");


	int n;
	fin >> n;

	int t, val;
	for(int i = 0; i < n; i++) {

		fin >> t >> val;

		if(t == 1) {
		 	add(val);
		}
		else if (t == 3) {
			if(is(val)) fout << "1\n";
			else fout << "0\n";
		}
		else {
			del(val);
		}
	}

	
	


	return 0;
}