Pagini recente » Cod sursa (job #2309146) | Cod sursa (job #2968808) | Cod sursa (job #1738294) | Cod sursa (job #171928) | Cod sursa (job #402024)
Cod sursa(job #402024)
#include<fstream>
#include<list>
#include<vector>
using namespace std;
const char iname[]="hashuri.in";
const char oname[]="hashuri.out";
ifstream f(iname);
ofstream g(oname);
class hash
{
public:
int mod;
vector<list<int> > c;
hash()
{
mod=679227;
c.resize(mod);
}
hash(int x)
{
mod=x;
c.resize(mod);
}
list<int>::iterator find(int x)
{
int y=x%mod;
for(list<int>::iterator it=c[y].begin();it!=c[y].end();++it)
if(*it==x)
return it;
return c[0].end();
}
void insert(int x)
{
int y=x%mod;
if(find(x)==c[0].end())
c[y].push_back(x);
}
void erase(int x)
{
int y=x%mod;
list<int>::iterator it=find(x);
if(it!=c[0].end())
c[y].erase(it);
}
} H(414977);
int n,x,y,i;
int main()
{
f>>n;
for(i=1;i<=n;++i)
{
f>>x>>y;
if(x==1)
H.insert(y);
if(x==2)
H.erase(y);
if(x==3)
if(H.find(y)!=H.c[0].end())
g<<"1\n";
else
g<<"0\n";
}
f.close();
g.close();
return 0;
}