Pagini recente » Cod sursa (job #724800) | Cod sursa (job #2316741) | Cod sursa (job #382160) | Cod sursa (job #1963031) | Cod sursa (job #911151)
Cod sursa(job #911151)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
#define MOD 60000
int n,i,k,poz,x;
vector < vector <long long> > h;
int hashh(long long x);
int verificare(long long x)
{
int i;
if (h[hashh(x)].size() >0 )
{
for (i=0;i<=h[hashh(x)].size()-1;i++)
{
if (h[hashh(x)][i]==x)
{
poz=i;
return 1;
}
}
}
return 0;
}
void stergere(long long x)
{
long long aux;
if (verificare(x)==1)
{
aux=h[hashh(x)][poz];
h[hashh(x)][poz]=h[hashh(x)][h[hashh(x)].size()-1];
h[hashh(x)][h[hashh(x)].size()-1]=aux;
h[hashh(x)].pop_back();
}
}
void adaugare(long long x)
{
h[hashh(x)].push_back(x);
}
int hashh(long long x)
{
long y;
y=x>>1;
y*=5;
y=y<<2;
y*=3;
y=y%MOD;
return int(y);
}
int main()
{
f>>n;
h.resize(MOD);
for (i=1;i<=n;i++)
{
f>>k;
f>>x;
if (k==1) adaugare(x);
if (k==2) stergere(x);
if (k==3) g<<verificare(x)<<'\n';
}
f.close();
g.close();
return 0;
}