Cod sursa(job #3358021)

Utilizator TestLicenta123Test Test TestLicenta123 Data 13 iunie 2026 23:03:49
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <fstream>
#include <vector>
#include <list>
#include <algorithm>

const int P = 1000003;

int hash(int x) {
    return x % P;
}

int main() {
    std::ifstream fin("hashuri.in");
    std::ofstream fout("hashuri.out");

    int N;
    fin >> N;

    std::vector<std::list<int>> table(P);

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

        int h = hash(x);
        auto& lst = table[h];

        if (op == 1) {
            if (std::find(lst.begin(), lst.end(), x) == lst.end()) {
                lst.push_back(x);
            }
        } else if (op == 2) {
            auto it = std::find(lst.begin(), lst.end(), x);
            if (it != lst.end()) {
                lst.erase(it);
            }
        } else if (op == 3) {
            if (std::find(lst.begin(), lst.end(), x) != lst.end()) {
                fout << "1\n";
            } else {
                fout << "0\n";
            }
        }
    }

    return 0;
}