Cod sursa(job #1521366)

Utilizator blasterzMircea Dima blasterz Data 10 noiembrie 2015 12:01:33
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <cstdio>
#include <set>

#define MAXH 666013

using namespace std;
int T;

set<int> table[MAXH];

inline int hashFunction(int val) {
    return val % MAXH;
}

void insert(int val) {
    int h = hashFunction(val);
    table[h].insert(val);
}

void remove(int val) {
    int h = hashFunction(val);
    table[h].erase(val);
}

bool find(int val) {
    int h = hashFunction(val);
    return table[h].find(val) != table[h].end();
}



int main() {
    freopen ("hashuri.in", "r", stdin);
    freopen ("hashuri.out", "w",stdout);
    int op, val;

    scanf ("%d\n", &T);
    
    while (T--) {
        scanf ("%d %d\n", &op, &val);
        if (op == 1) {
            insert(val);
        }
        if (op == 2) {
            remove(val);
        }
        if (op == 3) {
            printf ("%d\n", find(val));
        }
    }
   
}