Cod sursa(job #3141803)

Utilizator Tudor_EnacheEnache Tudor Tudor_Enache Data 16 iulie 2023 18:31:14
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include<fstream>
#include <vector>
using namespace std;

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

const int dim = 666013;


vector <int> H[dim];

int hash_function(int x){
    return x % dim;
}
bool cauta(int x){
    int h = hash_function(x);
    for (auto it:H[h])
        if (it == x)
        return 1;
    return 0;
}

void adauga(int num){
    int h = hash_function(num);
    if (cauta(num) == 0)
        H[h].push_back(num);

}

void sterge(int x){
    int h = hash_function(x);
    for (int i = 0; i < H[h].size();++i){
        if (H[h][i] == x){
            H[h].erase(H[h].begin() +i);
            break;
        }

    }
}

int main(){
    int op, x,q;
    cin >> q;
    while (q--){
        cin >> op >> x;
        if (op == 1)
            adauga(x);
        if (op == 2)
            sterge(x);
        if (op == 3){
            cout <<cauta(x) << endl;
        }
    }
}