Cod sursa(job #948206)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 9 mai 2013 18:09:45
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <cstdio>
#include <cassert>

#include <algorithm>
#include <set>

using namespace std;

class Hash {
  public:
    Hash() {}

    void Insert(const int value) {
        table[GetKey(value)].insert(value);
    }

    void Erase(const int value) {
        table[GetKey(value)].erase(value);
    }

    bool Search(const int value) {
        return table[GetKey(value)].find(value) != table[GetKey(value)].end();
    }
  private:
    static const int U = 666013;

    set<int> table[U];

    static int GetKey(const int value) {
        return value % U;
    }
};

Hash H;

int main() {
    assert(freopen("hashuri.in", "r", stdin));
    assert(freopen("hashuri.out", "w", stdout));
    int N; assert(scanf("%d", &N) == 1);
    for (; N > 0; --N) {
        int Type, X; assert(scanf("%d %d", &Type, &X) == 2);
        if (Type == 1)
            H.Insert(X);
        if (Type == 2)
            H.Erase(X);
        if (Type == 3)
            printf("%d\n", H.Search(X));
    }
    return 0;
}