Cod sursa(job #799677)

Utilizator toniobFMI - Barbalau Antonio toniob Data 19 octombrie 2012 19:30:04
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
#include <fstream>
#include <vector>
using namespace std;

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

const int modulo = 666317;
struct hash {
    vector <int> v[modulo+1];

    /*hash () {

    }*/

    void insert (int x) {
        v[x % modulo].push_back(x);
    }

    void erase (int x) {
        int xmod = x % modulo;
        for (vector<int>::iterator it = v[xmod].begin(); it != v[xmod].end(); ++it) {
            if (*it == x) {
                //int aux = *it;
                *it = v[xmod].back();
                //v[xmod].back() = aux;
                v[xmod].pop_back();
                return;
            }
        }
    }

    bool exist (int x) {
        int xmod = x % modulo;
        for (vector<int>::iterator it = v[xmod].begin(); it != v[xmod].end(); ++it) {
            if (*it == x) {
                return true;
            }
        }
        return false;
    }
};
int n;
hash h;

void citire () {
    in >> n;

    int op,x;
    while (n--) {
        in >> op >> x;

        if (op == 1) {
            h.insert (x);
        }
        if (op == 2) {
            h.erase (x);
        }
        if (op == 3) {
            out << h.exist (x) << '\n';
        }
    }
}

int main () {
    citire ();

    return 0;
}