Cod sursa(job #2746942)

Utilizator truscalucaLuca Trusca truscaluca Data 28 aprilie 2021 18:18:32
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.04 kb
#include <iostream>
#include <vector>

using namespace std;

const int mod = 666013;

vector<int> v[mod];
int q, cod, x;

bool eInLista(int nr) {
    int xHash = nr % mod;
    for (auto x : v[xHash]) {
        if (x == nr) {
            return true;
        }
    }
    return false;
}

int main() {
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    // Input rapid
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> cod >> x;

        int xHash = x % mod;

        if (cod == 1) {
            if (!eInLista(x)) {
                v[xHash].push_back(x);
            }
        } else if (cod == 2) {
            int indexDeSters = -1;
            for (auto it = v[xHash].begin(); it != v[xHash].end(); it++) {
                if (x == *it) {
                    v[xHash].erase(it);
                    break;
                }
            }
        } else if (cod == 3) {
            cout << (eInLista(x) ? "1" : "0") << "\n";
        }
    }
    return 0;
}