Cod sursa(job #425727)

Utilizator slayer4uVictor Popescu slayer4u Data 25 martie 2010 23:53:56
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

#define P 100007

//multiset <int> hash[P];
vector <int> hash[P];

long n, code, x, mod;

int main()
{
	freopen ("hashuri.in", "rt", stdin);
	freopen ("hashuri.out", "wt", stdout);

	scanf("%ld", &n);
	for (long i = 0; i < n; ++i)
	{
		scanf("%ld %ld", &code, &x);
		mod = x % P;

		if (code == 3)
		{
			long found = 0;
			for (long j = 0; j < hash[mod].size() && !found; ++j)
				if (x == hash[mod][j])
					found = 1;
			if (found)
				printf("1\n");
			else
				printf("0\n");
		}
		else
		if (code == 1)
			hash[mod].push_back(x);
		else
		{
			for (long j = 0; j < hash[mod].size(); ++j)
				if (x == hash[mod][j])
				{
					hash[mod].erase(hash[mod].begin() + j);
					break;
				}
		}

		/*
		if (code == 3)
			printf("%ld\n", hash[mod].find(x) != hash[mod].end());
		else
		if (code == 1)
			hash[mod].insert(x);
		else
			if (hash[mod].find(x) != hash[mod].end())
				hash[mod].erase(hash[mod].find(x));
		*/
	}

	return 0;
}