Pagini recente » Cod sursa (job #1623820) | Cod sursa (job #1493733) | Cod sursa (job #143786) | Cod sursa (job #1679123) | Cod sursa (job #1337603)
#include <fstream>
#include <iostream>
#include <list>
#define MOD 666013
using namespace std;
list<long> mhash[MOD];
long n;
long h(long x)
{
return x%MOD;
}
list<long>::iterator search(long x)
{
long h_x=h(x);
for(list<long>::iterator it=mhash[h_x].begin(), end=mhash[h_x].end(); it!=end; ++it)
if((*it)==x) return it;
return (list<long>::iterator)0;
}
list<long>::iterator add(long x)
{
long h_x=h(x);
if(search(x)==(list<long>::iterator)0)
{
mhash[h_x].push_back(x);
return mhash[h_x].end();
}
return (list<long>::iterator)0;
}
short remove(long x)
{
long h_x=h(x);
list<long>::iterator pos=search(x);
if(pos!=(list<long>::iterator)0)
{
mhash[h_x].erase(pos);
return 1;
}
return 0;
}
void print()
{
for(long i=0; i<MOD; ++i)
if(!mhash[i].empty())
{
for(list<long>::iterator it=mhash[i].begin(), end=mhash[i].end(); it!=end; ++it)
cout<<(*it)<<' ';
cout<<'\n';
}
}
int main()
{
ifstream in("hashuri.in");
ofstream out("hashuri.out");
short op, x;
in>>n;
for(long i=0; i<n; ++i)
{
in>>op>>x;
switch(op)
{
case 1: add(x);
break;
case 2: remove(x);
break;
case 3: if(search(x)!=(list<long>::iterator)0) out<<"1\n";
else out<<"0\n";
break;
}
//cout<<'\n';
// print();
}
in.close(); out.close();
return 0;
}