Cod sursa(job #604371)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 22 iulie 2011 00:24:20
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.32 kb
#include <iostream>
#include <vector>

#define U 666013

using namespace std;

vector <int> Hash[U];

int Search (int X)
{
    int Key=X%U;
    for (unsigned i=0; i<Hash[Key].size (); ++i)
    {
        if (Hash[Key][i]==X)
        {
            return i;
        }
    }
    return -1;
}

void Insert (int X)
{
    int Key=X%U;
    if (Search (X)==-1)
    {
        Hash[Key].push_back (X);
    }
}

void Delete (int X)
{
    int Key=X%U;
    if (Search (X)!=-1)
    {
        for (vector <int> :: iterator Y=Hash[Key].begin (); Y!=Hash[Key].end (); ++Y)
        {
            if (*Y==X)
            {
                Hash[Key].erase (Y);
                return;
            }
        }
    }
}

int main()
{
    freopen ("hashuri.in", "r", stdin);
    freopen ("hashuri.out", "w", stdout);
    int N;
    scanf ("%d", &N);
    for (; N>0; --N)
    {
        int Type, X;
        scanf ("%d %d", &Type, &X);
        if (Type==1)
        {
            Insert (X);
        }
        if (Type==2)
        {
            Delete (X);
        }
        if (Type==3)
        {
            if (Search (X)==-1)
            {
                printf ("0\n");
            }
            else
            {
                printf ("1\n");
            }
        }
    }
    return 0;
}