Cod sursa(job #2642965)

Utilizator marius004scarlat marius marius004 Data 17 august 2020 23:12:56
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

const int PRIME = 101'839;

int n, type, nr;
vector < int > set[PRIME];

vector<int>::iterator Find(const int& value) {

    const int Hash = value % PRIME;

    for(vector<int>::iterator it = set[Hash].begin(); it != set[Hash].end();++it)
        if(*it == value)
            return it;

    return set[Hash].end();
}

void Insert(const int& value) {
    const int Hash = value % PRIME;

    if(Find(value) == set[Hash].end())
        set[Hash].push_back(value);
}

void Erase(const int& value) {
    const int Hash = value % PRIME;
    auto it = Find(value);

    if(it != set[Hash].end())
        set[Hash].erase(it);
}

int main() {

    f >> n;

    while(n--) {
        f >> type >> nr;

        if(type == 1)
            Insert(nr);
        else if(type == 2)
            Erase(nr);
        else
            g << (Find(nr) != set[ nr % PRIME ].end()) << '\n';
    }

    return 0;
}