Pagini recente » Cod sursa (job #341638) | Cod sursa (job #1411426) | Cod sursa (job #1391015) | Cod sursa (job #408311) | Cod sursa (job #1775220)
#include <cstdio>
#define in "hashuri.in"
#define out "hashuri.out"
#define MOD 1027753
using namespace std;
int n, op, val, hashTable[MOD];
inline void init()
{
for(int i = 0; i< MOD; ++i) hashTable[i] = -1;
}
void addHash(const int &value)
{
int key = value%MOD;
while(hashTable[key] != -1)
{
if(hashTable[key] == value) return ;
++key;
if(key == MOD) key = 0;
}
hashTable[key] = value;
}
void removeHash(const int &value)
{
int key = value%MOD;
while(hashTable[key] != -1)
{
if(hashTable[key] == value)
{
hashTable[key] = -1;
return ;
}
++key;
if(key == MOD) key = 0;
}
}
int checkHash(const int &value)
{
int key = value%MOD;
while(hashTable[key] != -1)
{
if(hashTable[key] == value) return 1;
++key;
if(key == MOD) key = 0;
}
return 0;
}
int main()
{
freopen(in, "r", stdin);
freopen(out, "w", stdout);
init();
scanf("%d", &n);
for(int i = 1; i<= n; ++i)
{
scanf("%d %d", &op, &val);
if(op == 1) addHash(val);
if(op == 2) removeHash(val);
if(op == 3) printf("%d\n", checkHash(val));
}
}