Pagini recente » Cod sursa (job #2912336) | Cod sursa (job #1596331) | Cod sursa (job #1111064) | Cod sursa (job #2811640) | Cod sursa (job #2276743)
#include <stdio.h>
#include <map>
#include <set>
#include <fstream>
using namespace std;
int N;
#define H_BITS 19 // Hashtable size
#define H_SHIFT (32-H_BITS)
#define H_SHIFT_64 (64-H_BITS)
unsigned int hash32(unsigned int x) {
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;
return x>>H_SHIFT;
}
unsigned int hash64(unsigned int x) {
long long y = (long long)x * 2654435761;
return y>>H_SHIFT_64;
}
set<int> hashtab[1<<H_BITS];
unsigned int hashrob(unsigned int a)
{
a = (a+0x7ed55d16) + (a<<12);
a = (a^0xc761c23c) ^ (a>>19);
a = (a+0x165667b1) + (a<<5);
a = (a+0xd3a2646c) ^ (a<<9);
a = (a+0xfd7046c5) + (a<<3);
a = (a^0xb55a4f09) ^ (a>>16);
return a>>H_SHIFT;
}
int main()
{
//ifstream input("hashuri.in");
ifstream input("hashuri.in");
ofstream output("hashuri.out");
int i, tip, x;
input >> N;
long long y;
unsigned int slot;
for (i = 1; i <= N; i++)
{
input >> tip >> x;
//slot = hash32(x);
//y = (long long)x * 2654435761;
//slot=y>>H_SHIFT_64;
slot = hashrob(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;
}