Cod sursa(job #2246301)

Utilizator akumariaPatrascanu Andra-Maria akumaria Data 26 septembrie 2018 21:58:57
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.35 kb
#include <cstdio>
#include <vector>

#define MAXSIZE 666013

using namespace std;

vector<vector<int>> htable(MAXSIZE);


void add_el(int x)
{
    int poz = x % MAXSIZE;
    htable[poz].push_back(x);
}

void del_el(int x)
{
    int poz = x % MAXSIZE;
    for(vector<int>::iterator it = htable[poz].begin(); it != htable[poz].end(); ++it)
        if(*it == x)
        {
            htable[poz].erase(it);
            return;
        }
}

bool find_el(int x)
{
    int poz = x % MAXSIZE;
    for(auto it = htable[poz].begin(); it != htable[poz].end(); ++it)
        if(*it == x)
            return 1;
    return 0;
}

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

    int n, i, comm, x;

    scanf("%d", &n);

    for(i=0; i<n; ++i)
    {
        scanf("%d", &comm);
        switch (comm)
        {
            case 1:
            {
                scanf("%d", &x);
                add_el(x);
                continue;
            }
            case 2:
            {
                scanf("%d", &x);
                del_el(x);
                continue;
            }
            case 3:
            {
                scanf("%d", &x);
                printf("%d\n", find_el(x));
            }
        }
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}