Cod sursa(job #2627164)

Utilizator MevasAlexandru Vasilescu Mevas Data 10 iunie 2020 00:30:58
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <vector>
#include <fstream>

#define MOD 999983

using namespace std;

vector<int> map[MOD];

int find(int x) {
    int hash = x % MOD;
    vector<int>::iterator it;

    for(int i = 0; i < map[hash].size(); i++)
        if(map[hash][i] == x)
            return i;

    return -1;
}

void insert(int x) {
    int hash = x % MOD;
    if(find(x) == -1)
        map[hash].push_back(x);
}

void erase(int x) {
    int hash = x % MOD;
    auto i = find(x);

    if(i != -1)
        map[hash].erase(map[hash].begin() + i);
}

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

    int op, x, n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%d%d", &op, &x);
        if(op == 1) {
            insert(x);
            continue;
        }
        if(op == 2) {
            erase(x);
            continue;
        }
        printf("%d\n", find(x) != -1);
    }

    return 0;
}