Cod sursa(job #2744785)

Utilizator thatnickkNicu-Victor Ardeleanu thatnickk Data 25 aprilie 2021 02:52:40
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.33 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

// struct node{
//     int value;
//     node *next_node;
//     node *prev_node;
// }

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

vector<vector<int>> hashul_meu(666013);
int n, op_type, x;

int get_hash_value(int y){
    return y%666013;
}

void adaugare(int y){
    hashul_meu[y%666013].push_back(x);
}

void stergere(int y){
    for (int i = 0; i < hashul_meu[get_hash_value(y)].size(); i++){
        if (hashul_meu[get_hash_value(y)][i] == y){
            hashul_meu[get_hash_value(y)].erase(hashul_meu[get_hash_value(y)].begin() + i);
            break;
        }
    }
}

int cautare(int y){
    for (int i = 0; i < hashul_meu[get_hash_value(y)].size(); i++){
        if (hashul_meu[get_hash_value(y)][i] == y){
            return 1;
        }
    }
    return 0;
}

int main(){
    fin >> n;
    for (int i = 0; i < n; i++){
        fin >> op_type;
        switch (op_type){
            case 1:
                fin >> x;
                adaugare(x);
                break;
            case 2:
                fin >> x;
                stergere(x);
                break;
            case 3:
                fin >> x;
                fout << cautare(x) << '\n';
                break;
        }
    }
}