Cod sursa(job #2533612)

Utilizator SqueekDanielTodasca Daniel SqueekDaniel Data 29 ianuarie 2020 14:34:51
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <bits/stdc++.h>

const int prime = 666013;
class HashSet {
public:
    HashSet() {}

    void insert(int value) {
        if (!contains(value)) table[hash(value)].push_back(value);
    }
    void erase(int value) {
        table[hash(value)].remove(value);
    }
    bool contains(int value) {
        int v = hash(value);
        for (auto &it:table[v]) if (it == value) return true;
        return false;
    }

private:
    std::list <int> table[prime];
    inline int hash(int x) { return (x%prime + prime)%prime; }
}   set;

std::ifstream input ("hashuri.in");
std::ofstream output("hashuri.out");

int main()
{
    int Q;  input >> Q;
    int op, x;
    while (Q--) {
        input >> op >> x;
        if (op == 1) set.insert(x);
        else if (op == 2) set.erase(x);
        else if (op == 3) output << set.contains(x) << '\n';
    }

    return 0;
}