Cod sursa(job #777312)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 11 august 2012 20:21:57
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in ("hashuri.in");
ofstream out ("hashuri.out");

const int MOD = 666013;

vector <int> hash[MOD + 1];

inline vector <int> :: iterator find (int x)
{
	vector <int> :: iterator it;
	x %= MOD;
	
	for (it = hash[x].begin (); it != hash[x].end (); ++it)
		if (*it == x)
			return it;
		
	return hash[x].end ();
}

inline void insert (int x)
{
	int x2 = x % MOD;
	
	if (find (x2) != hash[x2].end ())
		hash[x2].push_back (x);
}

inline void del (int x)
{
	int x2 = x % MOD;
	vector <int> :: iterator it = find (x);
	
	if (it != hash[x2].end ())
		hash[x2].erase (it);
}

int main ()
{
	int N, tip, x;
	
	for (in >> N; N; -- N){
		in >> tip >> x;
		
		if (tip == 1)
			insert (x);
		
		if (tip == 2)
			del (x);
		
		if (tip == 3)
			out << (find (x) != hash[x % MOD].end ()) << "\n";
	}
	
	return 0;
}