Cod sursa(job #2038308)

Utilizator cyg_ieeuVasile Radu-Andrei cyg_ieeu Data 13 octombrie 2017 16:32:37
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
const int M = 666013;
vector <int> TA[M + 5];
vector <int> :: iterator it;
int h(int key)
{
	return key % M;
}
int main()
{
	freopen("hashuri.in", "r",stdin);
	freopen("hashuri.out", "w",stdout);
    int n,tip,x,a;
    scanf("%d", &n);
    for(int i = 1;i <= n;i++)
	{
		scanf("%d%d", &tip, &x);
		a = h(x);
		if(tip == 1)
			TA[a].push_back(x);
		else if(tip == 2)
		{
			it = find(TA[a].begin(),TA[a].end(),x);
			if(it != TA[a].end())
				TA[a].erase(it);
		}
		else if(tip == 3)
		{
			it = find(TA[a].begin(),TA[a].end(),x);
			if(it != TA[a].end())
				printf("1\n");
			else
				printf("0\n");
		}
	}
    return 0;
}