Pagini recente » Cod sursa (job #2735925) | Cod sursa (job #2947117) | Cod sursa (job #1418406) | Cod sursa (job #2843762) | Cod sursa (job #1775218)
#include <cstdio>
#define in "hashuri.in"
#define out "hashuri.out"
#define MOD 1027753
using namespace std;
int n, op, val, hashTable[MOD];
void addHash(const int &value)
{
int key = value%MOD;
while(hashTable[key])
{
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])
{
if(hashTable[key] == value)
{
hashTable[key] = 0;
return ;
}
++key;
if(key == MOD) key = 0;
}
}
int checkHash(const int &value)
{
int key = value%MOD;
while(hashTable[key])
{
if(hashTable[key] == value) return 1;
++key;
if(key == MOD) key = 0;
}
return 0;
}
int main()
{
freopen(in, "r", stdin);
freopen(out, "w", stdout);
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));
}
}