Cod sursa(job #1211745)

Utilizator vladmatei.nfoVlad Matei vladmatei.nfo Data 23 iulie 2014 11:25:22
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.33 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <time.h>
#include <stdlib.h>
#define lth 25999

using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n,r;
vector <int> hsh[50000];

void initKey()
{
    r = rand() % 1000;
}

int getKey(int a)
{
    return (a + r) % lth;
}

bool find(int b)
{
    int k = getKey(b);
    for(int i = 0; i < hsh[k].size(); i++)
    {
        if(hsh[k][i] == b)
        {
            return true;
        }
    }
    return false;
}

void insert(int b)
{
    if(find(b) == false)
    {
        int key = getKey(b);
        hsh[key].push_back(b);
    }
}

void remove(int b)
{
    int k = getKey(b);
    if(find(b) == false)
    {
        return;
    }
    for(int i = 0; i < hsh[k].size(); i++)
    {
        if(hsh[k][i] == b)
        {
            hsh[k].erase(hsh[k].begin() + i);
        }
    }
}

void read()
{
    int a,b;

    in>>n;

    for(int i = 1; i <= n; i++)
    {
        in >> a >> b;
        if(a == 1)
        {
            insert(b);
        }
        else if(a == 2)
        {
            remove(b);
        }
        else if(a == 3)
        {
            if(find(b) == true)
            {
                out<<"1\n";
            }
            else
            {
                out<<"0\n";
            }
        }
    }
}

int main()
{
    read();
    return 0;
}