Cod sursa(job #2734065)

Utilizator vladstefanVlad Oros vladstefan Data 31 martie 2021 12:36:21
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb

// problema hashuri

#include <fstream>
#include <algorithm>
#include <vector>

#define Div 100000
#define NMaxDiv 20000 // numarul maxim de clase de caturi posibile

using namespace std;

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

int n;
vector<int> Hash[NMaxDiv];

void Insert(int x) {
    Hash[x / Div].push_back(x);
}

void Delete(int x) {
    auto p = find(Hash[x / Div].begin(), Hash[x / Div].end(), x);
    if (p != Hash[x / Div].end()) Hash[x / Div].erase(p);
}

bool Find(int x) {
    auto p = find(Hash[x / Div].begin(), Hash[x / Div].end(), x);
    return (p != Hash[x / Div].end());
}

int main() {
    int p, x;
    for (fin >> n; n; --n) {
        fin >> p >> x;
        if (p == 1) Insert(x);
        else if (p == 2) Delete(x);
        else fout << Find(x) << '\n';
    }
}