Cod sursa(job #586697)

Utilizator dushmiMihai-Alexandru Dusmanu dushmi Data 2 mai 2011 19:38:11
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.24 kb
#include <cstdio>
#include <vector>

using namespace std;

const int MOD = 711713;

vector <int> hash[MOD + 3];

vector <int> :: iterator find_hash(int x) {
    int r = x % MOD;

    for (vector <int> :: iterator it = hash[r].begin(); it != hash[r].end(); ++ it)
        if (*it == x)
            return it;

    return hash[r].end();
}

void insert_hash(int x) {
    vector <int> :: iterator it = find_hash(x);
    int r = x % MOD;

    if (it == hash[r].end())
        hash[r].push_back(x);
}

void erase_hash(int x) {
    vector <int> :: iterator it = find_hash(x);
    int r = x % MOD;

    if (it != hash[r].end())
        hash[r].erase(it);
}

void query_hash(int x) {
    vector <int> :: iterator it = find_hash(x);
    int r = x % MOD;

    if (it == hash[r].end())
        printf("0\n");
    else
        printf("1\n");
}

int main() {
    int n, tip, nb;
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d%d", &tip, &nb);
        if (tip == 1)
            insert_hash(nb);
        else if (tip == 2)
            erase_hash(nb);
        else
            query_hash(nb);
    }
    return 0;
}