Cod sursa(job #2794750)

Utilizator Razvan48Capatina Razvan Nicolae Razvan48 Data 5 noiembrie 2021 13:05:25
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.23 kb
#include <fstream>
#include <vector>

using namespace std;

class HashSet
{
public:

  void Insert(int x)
  {
    int Hash = x % this->MODULO;

    if (!this->Find(x))
      this->resturi[Hash].push_back(x);
  }

  bool Find(int x)
  {
    int Hash = x % this->MODULO;

    for (int i = 0; i < this->resturi[Hash].size(); i++)
      if (this->resturi[Hash][i] == x)
        return true;

    return false;
  }

  void Erase(int x)
  {
    int Hash = x % this->MODULO;

    for (int i = 0; i < this->resturi[Hash].size(); i++)
    {
      if (this->resturi[Hash][i] == x)
      {
        this->resturi[Hash][i] = this->resturi[Hash].back();
        this->resturi[Hash].pop_back();

        return;
      }
    }
  }

private:

  static const int MODULO = 666013;
  vector<int> resturi[MODULO];

};

HashSet hs;

int main()
{
  ifstream in("hashuri.in");
  ofstream out("hashuri.out");

  int n;
  in >> n;

  for (int i = 1; i <= n; i++)
  {
    int op, x;
    in >> op >> x;

    if (op == 1)
      hs.Insert(x);
    else if (op == 2)
      hs.Erase(x);
    else
    {
      if (hs.Find(x))
        out << 1 << '\n';
      else
        out << 0 << '\n';
    }
  }

  return 0;
}