Cod sursa(job #2745316)

Utilizator Dantelogus99Gruia Gabriel Dantelogus99 Data 26 aprilie 2021 13:03:04
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int prim = 105683;
unsigned int n, op, x;
vector<int> h[prim];

bool search(int x)
{
    int bucket = x % prim;

    for (int i = 0; i < h[bucket].size(); i++)
        if (h[bucket][i] == x)
            return true;

    return false;
}

void append(int x)
{
    if (search(x) == false)
        h[x % prim].push_back(x);
}

void erase(int x)
{
    int bucket = x % prim;

    for (int i = 0; i < h[bucket].size(); i++)
    {
        if (h[bucket][i] == x)
        {
            h[bucket].erase(h[bucket].begin() + i);
            break;
        }
    }
}

int main()
{
    fin >> n;

    for (int i = 0; i < n; i++)
    {
        fin >> op >> x;

        if (op == 1)
            append(x);
        else
        {
            if (op == 2)
                erase(x);
            else
                fout << search(x) << '\n';
        }
    }
}