Cod sursa(job #2109119)

Utilizator inquisitorAnders inquisitor Data 19 ianuarie 2018 10:00:38
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <bits/stdc++.h>

using namespace std;

#define MOD 1000007

list<int> table[MOD];

void Delete(int N)
{
    int hashCode = N % MOD;

    for(auto it = table[hashCode].begin(); it != table[hashCode].end(); it++)
    {
        if(*it == N)
        {
            table[hashCode].erase(it);

            return;
        }
    }
}

bool Find(int N)
{
    int hashCode = N % MOD;

    for(auto it = table[hashCode].begin(); it != table[hashCode].end(); it++)
    {
        if(*it == N)
        {
            return true;
        }
    }

    return false;
}

void Insert(int N)
{
    int hashCode = N % MOD;

    if(!Find(N))
    {
        table[hashCode].push_back(N);
    }
}

int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    int T, Q, x; scanf("%d", &T);

    while(T--)
    {
        scanf("%d %d", &Q, &x);

        if(Q == 1) Insert(x);

        if(Q == 2) Delete(x);

        if(Q == 3) printf("%d\n", Find(x));
    }

    return 0;
}