Cod sursa(job #2591248)

Utilizator nTropicManescu Bogdan Constantin nTropic Data 30 martie 2020 02:13:30
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.27 kb
#include <bits/stdc++.h>

using namespace std;

const int mod = 666013;
int n, key, x;
vector<int> h[mod];

vector<int>::iterator find_value(int x) {
    int index = x % mod;
    for (vector<int>::iterator it = h[index].begin(); it != h[index].end(); it++)
        if (*it == x)
            return it;
    return h[index].end();
}

void insert_value(int x) {
    int index = x % mod;
    if (find_value(x) == h[index].end())
        h[index].push_back(x);
}

void erase_value(int x) {
    int index = x % mod;
    if (find_value(x) != h[index].end())
        h[index].erase(find_value(x));
}

bool contains_value(int x) {
    int index = x % mod;
    if (find_value(x) != h[index].end())
        return true;
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    cin >> n;
    while (n--) {
        cin >> key >> x;
        switch (key) {
            case 1:
                insert_value(x);
                break;
            case 2:
                erase_value(x);
                break;
            case 3:
                cout << contains_value(x) << "\n";
                break;
        }
    }
}