Cod sursa(job #1046899)

Utilizator PokerDawgCristian Popov PokerDawg Data 3 decembrie 2013 18:14:46
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

#define m 666013
#define k x % m

vector<int> h[m];

int cauta(int x)
{
	for (vector<int> ::iterator i = h[k].begin(); i != h[k].end(); i ++)
		if (*i == x)
			return i - h[k].begin();
	return -1;
}

void inserare(int x)
{
	if (cauta(x) == -1)
		h[k].push_back(x);
}

void stergere(int x)
{
	int p = cauta(x);
	if (p != -1)
	{
		h[k][p] = h[k].back();
		h[k].pop_back();
	}
}

int main()
{
	int n, a, b;
	in >> n;
	while (n)
	{
		in >> a >> b;

		if (a == 1)
			inserare(b);
		else if (a == 2)
			stergere(b);
		else if (a == 3)
		{
			if (cauta(b) == -1)
				out << 0 << endl;
			else
				out << 1 << endl;
		}

		n--;
	}

	in.close();
	out.close();

    return 0;
}