Pagini recente » Cod sursa (job #215858) | Cod sursa (job #2015977) | Cod sursa (job #659874) | Cod sursa (job #619412) | Cod sursa (job #1437566)
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#define MOD 666013
vector<int> liste[MOD];
int indexLista;
inline vector<int>::iterator exista(int element)
{
indexLista = element % MOD;
vector<int>::iterator it;
for (it = liste[indexLista].begin(); it != liste[indexLista].end(); ++it)
if (*it == element)
return it;
return liste[indexLista].end();
}
inline void adaugaElement(int element)
{
indexLista = element % MOD;
// nu exista, il adaugam
if (exista(element) == liste[indexLista].end())
liste[indexLista].push_back(element);
}
inline void stergeElement(int element)
{
indexLista = element % MOD;
vector<int>::iterator it = exista(element);
if (it != liste[indexLista].end())
{
liste[indexLista].erase(it);
}
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int nrOperatii;
int tip, element;
scanf("%d", &nrOperatii);
for (int i = 0; i < nrOperatii; ++i)
{
scanf("%d%d", &tip, &element);
if (tip == 1)
{
adaugaElement(element);
continue;
}
if (tip == 2)
{
stergeElement(element);
continue;
}
if (exista(element) != liste[element % MOD].end())
printf("1\n");
else
printf("0\n");
}
return 0;
}