Pagini recente » Cod sursa (job #1828639) | Cod sursa (job #167068) | Cod sursa (job #1684532) | Cod sursa (job #2733211) | Cod sursa (job #1374566)
#include <fstream>
#include <vector>
#define cheie 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n, op, x;
vector <int> L[cheie];
void hash_insert(int x);
vector <int>::iterator hash_find(int x);
void hash_erase(int x);
void hash_insert(int x){
int key = x % cheie;
if(hash_find(key) == L[key].end() )
L[key].push_back(x);
}
vector <int>::iterator hash_find(int x){
int key = x % cheie;
vector <int>::iterator it;
for(it = L[key].begin(); it != L[key].end(); it ++)
{
if(*it == x)
return it;
}
return it;
}
void hash_erase(int x){
int key = x % cheie;
vector <int>::iterator it = hash_find(key);
if(it != L[key].end())
{
swap(L[key][L[key].size() - 1], *it);
L[key].pop_back();
}
}
int main()
{
fin >> n;
for(int i = 1; i <= n; i ++)
{
fin >> op;
if(op == 1)
{
fin >> x;
hash_insert(x);
}
else
if(op == 2)
{
fin >> x;
hash_erase(x);
}
else
{
fin >> x;
if(hash_find(x) != L[x % cheie].end())
{
fout << "1" << '\n';
}
else
{
fout << "0" << '\n';
}
}
}
return 0;
}