Cod sursa(job #2658962)

Utilizator YusyBossFares Yusuf YusyBoss Data 15 octombrie 2020 16:44:52
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <fstream>
#include <vector>
#define MOD 666013

///1017932

using namespace std;

///1017932

ifstream cin ("hash.in");
ofstream cout ("hash.out");

///1017932

vector<int> hash[MOD];

///1017932

void add(int x) {
  int nr, i, n;
  nr = x % MOD;

  ///1017932

  i = 0;
  n = hash[nr].size();
  while (i < n && hash[nr][i] != x)
    i++;
  if (i == n)
    hash[nr].push_back(x);
}

///1017932

bool search(int x) {
  int nr, i, n;

  ///1017932

  i = 0;
  nr = x % MOD;
  n = hash[nr].size();
  while (i < n && hash[nr][i] != x)
    i++;
  if (i == n)
    return 0;
  return 1;
}

///1017932

void del(int x) {
  int nr, i, n;

  ///1017932

  i = 0;
  nr = x % MOD;
  n = hash[nr].size();
  while (i < n && hash[nr][i] != x)
    i++;
  if (i < n)
    hash[nr].erase(hash[nr].begin() + i);
}

///1017932

int main() {
  int n, x, op;
  cin >> n;

  ///1017932

  while (n--) {
    cin >> op >> x;
    if (op == 1)
      add(x);
    else if (op == 2)
      del(x);
    else
      cout << search(x) << "\n";
  }
  return 0;
}