Cod sursa(job #2567831)

Utilizator NotTheBatmanBruce Wayne NotTheBatman Data 3 martie 2020 19:06:15
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 kb
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

const int P = 777013;

vector <int> H[P];


bool InHash (int x)
{
    int r = x % P;
    for (auto it : H[r])
        if (it == x) return true;
    return false;
}

void Add (int x)
{
    if (!InHash(x))
    {
        int r = x % P;
        H[r].push_back(x);
    }
}

void Delete (int x)
{
    int r = x % P;
    for (int i = 0; i < H[r].size(); i++)
        if (H[r][i] == x)
        {
            swap(H[r][i], H[r][H[r].size() - 1]);
            H[r].pop_back();
            return;
        }
}

void Read ()
{
    ifstream fin ("hashuri.in");
    ofstream fout ("hashuri.out");
    int n;
    fin >> n;
    while (n--)
    {
        int op, x;
        fin >> op >> x;
        if (op == 1) Add(x);
        else if (op == 2) Delete(x);
        else fout << InHash(x) << "\n";
    }
    fout.close();
    fin.close();
}

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