Cod sursa(job #2591241)

Utilizator nTropicManescu Bogdan Constantin nTropic Data 30 martie 2020 01:40:51
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.1 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 f = x % mod;
    for (vector<int>::iterator it = h[f].begin(); it != h[f].end(); it++)
        if (*it == x)
            return it;
    return h[x].end();
}

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

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

bool contains_value(int x) {
    int f = x % mod;
    if (find_value(x) != h[f].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;
        if (key == 1)
            insert_value(x);
        else if (key == 2)
            erase_value(x);
        else
            cout << contains_value(x) << "\n";
    }
}