Pagini recente » Cod sursa (job #808491) | Cod sursa (job #799228) | Cod sursa (job #226854) | Cod sursa (job #803304) | Cod sursa (job #1000722)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int N = 666013;
vector<int> h[N] ;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
void doOp(int op, int param);
int main()
{
int nrOp = 0;
fin >> nrOp;
for(int i=0; i<nrOp; i++)
{
int op,param;
fin >> op;
fin >> param;
doOp(op,param);
}
return 0;
}
int getHash(int nr)
{
return (nr%N);
}
int inHashTable(int nr)
{
int inHashPosition = -1;
int hashKey = getHash(nr);
for(int i=0; i<h[hashKey].size(); i++)
if(h[hashKey].at(i) == nr)
{
inHashPosition=i;
break;
}
return inHashPosition;
}
void insertInHash(int nr)
{
h[getHash(nr)].push_back(nr);
}
void deleteFromHash(int nr, int position)
{
h[getHash(nr)].erase(h[getHash(nr)].begin() + position);
}
void doOp(int op, int param)
{
switch(op)
{
case 1:
{
if(inHashTable(param) == -1)
insertInHash(param);
break;
}
case 2:
{
int inHashPosition = inHashTable(param);
if(inHashPosition != -1)
{
deleteFromHash(param, inHashPosition);
}
break;
}
case 3:
{
if(inHashTable(param) != -1)
{
fout << '1' << '\n';
}
else
{
fout << '0' << '\n';
}
break;
}
}
}