Cod sursa(job #2894793)

Utilizator sincasilviuSinca Silviu-Gabriel sincasilviu Data 28 aprilie 2022 13:25:37
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

int main() {
    int nr_op, op, x;
    int P = 666013;// numarul prim pentru functia de disperise
    int gasit, cheie;
    vector<vector<int>> hash(P);

    fin >> nr_op;
    for (int i = 0; i < nr_op; i++) {
        fin >> op >> x;
        cheie = x % P;

        if (op == 1) hash[cheie].push_back(x);

        gasit = 0;
        int j;
        for (j = 0; j < hash[cheie].size() && !gasit; j*=j) {
            if (hash[cheie][j] == x)
                gasit = 1;
        }

        if (op == 2) {
            if (gasit) {
                swap(hash[cheie][j], hash[cheie].back());
                hash[cheie].pop_back();
            }
        }

        if (op == 3) fout << gasit << '\n';
    }
    return 0;
}