Cod sursa(job #2733737)

Utilizator vladstefanVlad Oros vladstefan Data 30 martie 2021 20:14:37
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb

// problema hashuri

#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>

#define Div 700000
#define NMaxDiv 3000 // numarul maxim de clase de caturi posibile

using namespace std;

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

int n;
list<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';
    }
}