Pagini recente » Cod sursa (job #617891) | Cod sursa (job #2248558) | Cod sursa (job #857073) | Cod sursa (job #3277784) | Cod sursa (job #2760138)
#include <fstream>
using namespace std;
const int K = 666019;
const int Nmax = 1e6 + 1;
int val[Nmax], urm[Nmax], lst[K], nr;
bool exista(int x)
{
int categoria = x % K;
int p = lst[categoria];
while (p != 0)
{
if (val[p] == x)
{
return true;
}
p = urm[p];
}
return false;
}
void adauga(int x)
{
if (exista(x))
{
return;
}
val[++nr] = x;
int categoria = x % K;
urm[nr] = lst[categoria];
lst[categoria] = nr;
}
void sterge(int x)
{
if (!exista(x))
{
return;
}
int categoria = x % K;
int p = lst[categoria];
while (p != 0)
{
if (val[p] == x)
{
val[p] = val[lst[categoria]];
lst[categoria] = urm[lst[categoria]];
return;
}
p = urm[p];
}
}
int main()
{
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int t;
fin >> t;
while (t--)
{
int op, x;
fin >> op >> x;
if (op == 1)
{
adauga(x);
}
else if (op == 2)
{
sterge(x);
}
else
{
fout << exista(x) << "\n";
}
}
return 0;
}