Cod sursa(job #1249356)

Utilizator okros_alexandruOkros Alexandru okros_alexandru Data 26 octombrie 2014 21:32:35
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.24 kb
#include <fstream>
#include <vector>

#define Nmax 200100
#define mod 666013

using namespace std;

class Hash {

    private:
        vector <int> V[mod];
        int index;

        void getIndex(int X) {

            index = X % mod;

        }

    public:
        Hash() {}

        int search(int X) {

            getIndex(X);

            for(int i = 0; i < V[index].size(); i++)
                if(V[index][i] == X)
                    return i;

            return -1;

        }

        void insert(int X) {

            if(search(X) == -1)
                V[index].push_back(X);

        }

        void remove(int X) {

            int position;

            if((position = search(X)) != -1)
                V[index].erase(V[index].begin() + position);

        }

};

Hash h;

int main() {

    int type, x, T;

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

    in >> T;

    while(T--) {

        in >> type >> x;

        switch(type) {
            case 1: h.insert(x); break;
            case 2: h.remove(x); break;
            case 3: out << (h.search(x) != -1) << '\n';
            }

        }

    in.close();
    out.close();

    return 0;

}