Cod sursa(job #780803)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 21 august 2012 21:23:20
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <cstdio>
#include <vector>

using namespace std;

const int U = 666013;

vector<int> H[U];

inline int Find(const int Value) {
    int Key = Value%U;
    for (vector<int>::iterator X = H[Key].begin(); X != H[Key].end(); ++X)
        if (*X == Value)
            return 1;
    return 0;
}

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

inline void Erase(const int Value) {
    int Key = Value%U;
    for (vector<int>::iterator X = H[Key].begin(); X != H[Key].end(); ++X) {
        if (*X == Value) {
            H[Key].erase(X);
            return;
        }
    }
}

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