Cod sursa(job #2975449)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 6 februarie 2023 15:55:50
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int HASH_VALUE = 999117;
vector<int> hashTable[HASH_VALUE];
int n, op, x;

int main() {
    fin >> n;
    for (int i = 1; i <= n; i++) {
        fin >> op >> x;
        int hash = x % HASH_VALUE;
        auto xAddress = find(hashTable[hash].begin(), hashTable[hash].end(), x);


        if (op == 1) {
            if (xAddress == hashTable[hash].end())
                hashTable[hash].push_back(x);
        } else if (op == 2) {
            if (xAddress != hashTable[hash].end())
                hashTable[hash].erase(xAddress);
        } else {
            fout << (xAddress != hashTable[hash].end()) << '\n';
        }
    }

    return 0;
}