Cod sursa(job #956951)

Utilizator SchumiDumitru Andrei Georgian Schumi Data 4 iunie 2013 10:14:36
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int MOD = 666013;

int n;
vector <int> hash[MOD];

void insert(int val) {
    int key = val % MOD;

    hash[key].push_back(val);
}

vector <int>::iterator find(int val) {
    int key = val % MOD;

    for (vector <int>::iterator it = hash[key].begin(); it != hash[key].end(); ++it)
        if (*it == val)
            return it;

    return hash[key].end();
}

void erase(int val) {
    int key = val % MOD;

    vector <int>::iterator it = find(val);

    if (it != hash[key].end())
        hash[key].erase(it);
}

int main() {
    f >> n;
    
    while (n--) {
        int type, val;

        f >> type >> val;

        if (type == 1)
            insert(val);
        else if (type == 2)
            erase(val);
        else {
            if (find(val) == hash[val % MOD].end())
                g << "0\n";
            else
                g << "1\n";
        }
    }

    return 0;
}