Cod sursa(job #3172845)

Utilizator SIret_LucaSiret Luca SIret_Luca Data 21 noiembrie 2023 13:03:43
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.04 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector<int> v[100001];

const int R=10007;

bool exista(int x) {
    int hash=x%R;
    for (auto elem: v[hash]) {
        if (elem==x) {
            return true;
        }
    }
    return false;
}

void adaug(int x) {
    int hash = x%R;
    if (!exista(x)) {
        v[hash].push_back(x);
    }
}

void sterg(int x) {
    int hash=x%R;
    for (auto it=v[hash].begin(); it!=v[hash].end(); ++it) {
        if (*it==x) {
            v[hash].erase(it);
            break;
        }
    }
}

int main() {
    int n, op, x;
    fin >> n;
    for (int i = 0; i < n; i++) {
        fin >> op >> x;
        if (op == 1) {
            adaug(x);
        }
        if (op == 2) {
            sterg(x);
        }
        if (op == 3) {
            if (exista(x)==1) {
                fout<<"1"<<'\n';
            }
            if (exista(x)==0) {
                fout<<"0"<<'\n';
            }
        }
    }
    fin.close();
    fout.close();
    return 0;
}