Pagini recente » Cod sursa (job #1708699) | Cod sursa (job #1268729) | Cod sursa (job #557092) | Cod sursa (job #2030278) | Cod sursa (job #2469631)
#include <iostream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
class Hash{
public:
// data structures
vector <int> H[MOD];
// methods
vector <int> :: iterator Find(int x);
void Insert(int x);
void Erase(int x);
};
vector <int> :: iterator Hash :: Find(int x)
{
int key = x % MOD;
vector <int> :: iterator it;
for(it = H[key].begin(); it != H[key].end(); ++it)
if(*it == x)
return it;
return H[key].end();
}
void Hash :: Insert(int x)
{
int key = x % MOD;
if(Find(x) == H[key].end())
H[key].push_back(x);
}
void Hash :: Erase(int x)
{
int key = x % MOD;
vector <int> :: iterator it = Find(x);
if(it != H[key].end())
H[key].erase(it);
}
int main()
{
Hash hash;
vector <int> :: iterator it;
int type, param, queries;
fin >> queries;
for(int i = 0 ; i < queries; i++)
{
fin >> type >> param;
if(type == 1)
hash.Insert(param);
if(type == 2)
hash.Erase(param);
if(type == 3)
{
it = hash.Find(param);
if(it != hash.H[param % MOD].end())
fout << 1 << "\n";
else
fout << 0 << "\n";
}
}
return 0;
}