Cod sursa(job #832305)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 10 decembrie 2012 12:24:15
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.26 kb
///timing 11:53
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

typedef long long i64;

i64 value;

class hash {
    int Key;
    vector <i64> * H;
    vector<i64>::iterator it;

    public:
        hash() { Key = 0; H = new vector<i64>[1]; };
        hash(int);
        void insert();
        void erase();
        int check();
};

hash :: hash(int K){
    Key = K;
    H = new vector <i64> [K];
}

void hash :: insert () {
    int X = value % Key;
    H[X].push_back(value);
}

void hash :: erase () {
    int X = value % Key;
    for(it = H[X].begin(); it != H[X].end(); it++)
        if(*it == value){
            H[X].erase(it);
            break;
        }
}

int hash :: check() {
    int X = value % Key;
    for(it = H[X].begin(); it != H[X].end(); it++)
        if(*it == value) return 1;
    return 0;
}

int main()
{
    hash A(666013);

    int N, operation;
    in >> N;

    while(N--){
        in >> operation >> value;
        switch (operation) {
            case 1: A.insert(); break;
            case 2: A.erase(); break;
            case 3: out << A.check() << "\n"; break;
        }
    }

    return 0;
}