Cod sursa(job #1875053)

Utilizator tudormaximTudor Maxim tudormaxim Data 10 februarie 2017 18:13:08
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.34 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");

const int mod = 666013;

class Hash {
private:
    vector <int> V[mod + 1];

public:
    inline vector <int> :: iterator Find(int val) {
        int key = val & mod;
        for (vector <int> :: iterator it = V[key].begin(); it != V[key].end(); it++) {
            if (*it == val) {
                return it;
            }
        }
        return V[key].end();
    }

    inline bool Exist(int val) {
        int key = val & mod;
        return Find(val) != V[key].end();
    }

    inline void Insert(int val) {
        int key = val & mod;
        if (Find(val) == V[key].end()) {
            V[key].push_back(val);
        }
    }

    inline void Erase(int val) {
        int key = val & mod;
        vector <int> :: iterator pos = Find(val);
        if (pos != V[key].end()) {
            V[key].erase(pos);
        }
    }
} H;

int main() {
    ios_base :: sync_with_stdio (false);
    int n, op, val;
    fin >> n;
    while (n--) {
        fin >> op >> val;
        if (op == 1) {
            H.Insert(val);
        } else if (op == 2) {
            H.Erase(val);
        } else {
            fout << H.Exist(val) << "\n";
        }
    }
    fin.close();
    fout.close();
    return 0;
}