Cod sursa(job #2533623)

Utilizator SqueekDanielTodasca Daniel SqueekDaniel Data 29 ianuarie 2020 14:55:53
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb

#include <bits/stdc++.h>


template <int prime>
class NonChainingHashTable {
public:
    NonChainingHashTable() {}

    void insert(int value)   { table[hash(value)] = true;  }
    void erase(int value)    { table[hash(value)] = false; }
    bool contains(int value) { return table[hash(value)];  }

private:
    bool table[prime];
    inline int hash(int x)  { return (x%prime + prime)%prime; }
};
NonChainingHashTable <666013> set;
NonChainingHashTable <928471> set2;
NonChainingHashTable <12228531> set3;

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), set2.insert(x), set3.insert(x);
        else if (op == 2) set.erase(x), set2.erase(x), set3.erase(x);
        else if (op == 3) output << (set.contains(x) + set2.contains(x) + set3.contains(x) >= 2) << '\n';
    }

    return 0;
}