Cod sursa(job #1587980)

Utilizator Ionut.popescuLiviu Rebreanu Ionut.popescu Data 2 februarie 2016 18:23:42
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <unordered_set>

using namespace std;

const int BITS = 16;
const int MASK = (1 << BITS) - 1;

unordered_set <int> H[1 << BITS];

static inline
void m_insert(const int &X) {
    H[(X >> 16) & MASK].insert(X & MASK);
}

static inline
bool m_find(const int &X) {
    return H[(X >> 16) & MASK].find(X & MASK) != H[(X >> 16) & MASK].end();
}

static inline
void m_erase(const int &X) {
    H[(X >> 16) & MASK].erase(X & MASK);
}

int main() {
    ifstream in("hashuri.in");
    in.tie(0);
    ios_base::sync_with_stdio(false);
    ofstream out("hashuri.out");
    int Q;
    int opType, arg;

    in >> Q;
    while (Q--) {
        in >> opType >> arg;
        if (opType == 1) {
            m_insert(arg);
        } else if (opType == 2) {
            m_erase(arg);
        } else {
            if (m_find(arg)) {
                out << "1\n";
            } else {
                out << "0\n";
            }
        }
    }
    in.close();
    out.close();

    return 0;
}