Pagini recente » Cod sursa (job #918362) | Cod sursa (job #560176) | Cod sursa (job #1652545) | Cod sursa (job #2152138) | Cod sursa (job #2736445)
#include <iostream>
#include <fstream>
#define maxx 1000005
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int prime = 9973;
int val[maxx], urm[maxx], lst[prime], nr;
void add(int x)
{
int bucket = x % prime;
nr += 1;
val[nr] = x;
urm[nr] = lst[bucket];
lst[bucket] = nr;
}
bool searchh(int x)
{
int bucket = x % prime;
int p = lst[bucket];
while(p != 0 && val[p] != x)
p = urm[p];
if (p)
return true;
return false;
}
void remove(int x)
{
int bucket = x % prime;
int p = lst[bucket];
while(p != 0 && val[p] != x)
p = urm[p];
if (p != 0)
{
swap(val[p], val[lst[bucket]]);
lst[bucket] = urm[lst[bucket]];
}
}
int main()
{
int operatii;
fin >> operatii;
while(operatii--)
{
int tip_operatie, val;
fin >> tip_operatie >> val;
if(tip_operatie == 1)
add(val);
if(tip_operatie == 2)
remove(val);
if(tip_operatie == 3)
fout << searchh(val) << '\n';
}
return 0;
}