Cod sursa(job #2636149)

Utilizator stormy_weatherelena cristina stormy_weather Data 16 iulie 2020 18:57:48
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.23 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

const int MOD = 666013;

int find_value(int val, vector <vector <int>> &hash) {
  int pos = val % MOD;

  for (int i = 0; i < (int) hash[pos].size(); i++)
    if (hash[pos][i] == val)
      return i;

  return -1;
}

void insert(int val, vector <vector <int>> &hash) {
  int pos = val % MOD;
  if (find_value(val, hash) == -1)
    hash[pos].push_back(val);
}

void erase(int val, vector <vector <int>> &hash) {
  int pos = val % MOD;
  int where = find_value(val, hash);
  if (where != -1)
    hash[pos].erase(hash[pos].begin() + where);
}

int present(int val, vector <vector <int>> &hash) {
  int where = find_value(val, hash);
  if (where == -1)
    return 0;
  return 1;
}

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

  int n; fin >> n;
  vector <pair <int, int>> op;
  for (int i = 0; i < n; i++) {
    int o, x; fin >> o >> x;
    op.push_back({o, x});
  }

  vector <vector <int>> hash(MOD, vector <int>());
  for (int i = 0; i < n; i++) {
    if (op[i].first == 1) {
      insert(op[i].second, hash);
    } else if (op[i].first == 2) {
      erase(op[i].second, hash);
    } else {
      fout << present(op[i].second, hash) << "\n";
    }
  }
}