Cod sursa(job #3318000)

Utilizator TimofeiFilipTimofei Filip Emanuel TimofeiFilip Data 26 octombrie 2025 15:08:13
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <algorithm>
#include<cstdio>
#include<vector>

using namespace std;
const int MOD = 666013;

vector<int> v[MOD]; // hash cu adresa

bool inHash(int x) {
    int position = x % MOD;
    for (auto element : v[position]) {
        if (element == x) {
            return true;
        }
    }
    return false;
}

void addElement(int x) {
    if (inHash(x))
        return;
    int position = x % MOD;
    v[position].push_back(x);
}
void deleteElement(int x) {
    if (!inHash(x))
        return;
    int position = x % MOD;
    auto it = find(v[position].begin(), v[position].end(), x);
    if (it != v[position].end()) {
        v[position].erase(it);
    }
}
int main(){
    int n;
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    scanf("%d",&n);

    for (int i = 0; i < n; i++) {
        int op, x;
        scanf("%d %d", &op, &x);
        if (op == 1) {
            addElement(x);
        }
        else if (op == 2) {
            deleteElement(x);
        }
        else {
            printf("%d\n",inHash(x));
        }
    }

    return 0;
}