Cod sursa(job #1775222)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 10 octombrie 2016 08:40:03
Problema Hashuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include <cstdio>

#define in "hashuri.in"
#define out "hashuri.out"
#define MOD 666013

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));
    }
}