Cod sursa(job #2646985)

Utilizator MatteoalexandruMatteo Verzotti Matteoalexandru Data 2 septembrie 2020 16:33:16
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.08 kb
/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>

using namespace std;

const int INF = 2e9;

class HashMap {
private:
    const static int MOD = 666013;
    vector <int> table[MOD];

public:
    bool Find(int elem) {
        int H = elem % MOD;

        for(vector <int> :: iterator it = table[H].begin(); it != table[H].end(); it++) {
            if(*it == elem)
                return true;
        }

        return false;
    }

    void Insert(int elem) {
        int H = elem % MOD;

        if(!Find(elem))
            table[H].push_back(elem);
    }

    void Erase(int elem) {
        int H = elem % MOD;

        for(vector <int> :: iterator it = table[H].begin(); it != table[H].end(); it++) {
            if(*it == elem) {
                table[H].erase(it);
                return;
            }
        }
    }
};
HashMap hm;

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

    int n;
    scanf("%d", &n);

    while(n--) {
        int t, x;
        scanf("%d%d", &t, &x);

        if(t == 1) hm.Insert(x);
        else if(t == 2) hm.Erase(x);
        else printf("%d\n", hm.Find(x));
    }
    return 0;
}