Pagini recente » Cod sursa (job #2578876) | Cod sursa (job #1579982) | Cod sursa (job #1499568) | Cod sursa (job #2764649) | Cod sursa (job #2276695)
#include <stdio.h>
#include <map>
#include <set>
#include <fstream>
using namespace std;
int N;
#define H_BITS 16 // Hashtable size
#define H_SHIFT (32-H_BITS)
unsigned int hash(unsigned int x) {
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;
return x>>H_SHIFT;
}
set<int> hashtab[1<<H_BITS];
int main()
{
ifstream input("hashuri.in");
ofstream output("hashuri.out");
int i, tip, x;
input >> N;
for (i = 1; i <= N; i++)
{
input >> tip >> x;
unsigned int slot = hash(x);
switch(tip){
case 1:
hashtab[slot].insert(x);
break;
case 2:
hashtab[slot].erase(x);
break;
case 3:
if(hashtab[slot].find(x) != hashtab[slot].end())
output << "1" << endl;
else
output << "0" << endl;
break;
}
}
input.close();
output.close();
return 0;
}