Cod sursa(job #2622312)

Utilizator MevasAlexandru Vasilescu Mevas Data 31 mai 2020 21:43:47
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <vector>
#include <fstream>

#define MOD 999983

using namespace std;

vector<int> map[MOD];

int find(int x) {
    int hash = x % MOD;
    vector<int>::iterator it;

    for(int i = 0; i < map[hash].size(); i++)
        if(map[hash][i] == x)
            return i;

    return -1;
}

void insert(int x) {
    int hash = x % MOD;
    if(find(x) == -1)
        map[hash].push_back(x);
}

void erase(int x) {
    int hash = x % MOD;
    auto i = find(x);

    if(i != -1)
        map[hash].erase(map[hash].begin() + i);
}

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

    int op, x, n;
    fin >> n;

    for(int i = 0; i < n; i++) {
        fin >> op >> x;
        if(op == 1) {
            insert(x);
            continue;
        }
        if(op == 2) {
            erase(x);
            continue;
        }
        fout << (find(x) != -1) << endl;
    }

    return 0;
}