Pagini recente » Cod sursa (job #2278406) | Cod sursa (job #951392) | Cod sursa (job #3203277) | Cod sursa (job #3191039) | Cod sursa (job #1092537)
#include <fstream>
#include <vector>
#define Key 100007
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int N;
vector < int > Hash[Key];
int H(int x)
{
int y=x+Key;
return (y-(y/Key)*Key);
}
bool Find(int x)
{
int list=H(x);
for(vector<int>::iterator it=Hash[list].begin(); it!=Hash[list].end(); ++it)
if( x == *it ) return 1;
return 0;
}
void Add(int x)
{
if ( !Find(x) ) Hash[x % Key].push_back(x);
}
void Delete(int x)
{
int list = H(x);
for (vector<int>::iterator it=Hash[list].begin(); it!=Hash[list].end(); ++it)
if ( x == *it )
{
Hash[list].erase(it);
return;
}
}
int main()
{
f>>N;
for (int i=1;i<=N;++i)
{
int tip,x;
f>>tip>>x;
if (tip==1)Add(x);
if (tip==2)Delete(x);
if (tip==3)g<<Find(x)<<'\n';
}
f.close();g.close();
return 0;
}