Pagini recente » Cod sursa (job #1753819) | Cod sursa (job #3135950) | Cod sursa (job #2312521) | Cod sursa (job #988327) | Cod sursa (job #2406276)
#include <iostream>
#include <fstream>
#include <vector>
#define KEY 666013
#define pb push_back
#define un unsigned
using namespace std;
vector<int> hash[KEY];
void insert(int &x)
{
int nivel=x%KEY;
for(un int i=0;i<hash[nivel].size();++i)
if(hash[nivel][i]==x)
return;
hash[nivel].pb(x);
}
void erase(int &x)
{
int nivel=x%KEY;
for(un int i=0;i<hash[nivel].size();++i)
if(hash[nivel][i]==x)
{
swap(hash[nivel][i],hash[nivel].back());
hash[nivel].pop_back();
return;
}
}
bool find(int &x)
{
int nivel=x%KEY;
for(un int i=0;i<hash[nivel].size();++i)
if(hash[nivel][i]==x)
return true;
return false;
}
int main()
{
int n;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>n;
for(int i=1;i<=n;++i)
{
int op,x;
f>>op>>x;
if(op==1)
insert(x);
if(op==2)
erase(x);
if(op==3)
g<<find(x)<<"\n";
}
return 0;
}