Cod sursa(job #883594)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 20 februarie 2013 10:31:39
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <cstdio>
#include <cassert>

#include <vector>

using namespace std;

typedef vector<int>::iterator it;

const int U = 666013;

vector<int> H[U];

inline int Search(int X) {
    int Key = X % U;
    for (it V = H[Key].begin(); V != H[Key].end(); ++V)
        if (*V == X)
            return 1;
    return 0;
}

inline void Insert(int X) {
    int Key = X % U;
    if (!Search(X))
        H[Key].push_back(X);
}

inline void Erase(int X) {
    int Key = X % U;
    for (it V = H[Key].begin(); V != H[Key].end(); ++V) {
        if (*V == X) {
            H[Key].erase(V);
            return;
        }
    }
}

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