Cod sursa(job #2922287)

Utilizator raresgherasaRares Gherasa raresgherasa Data 7 septembrie 2022 20:46:34
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>

using namespace std;

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

const int mod = 777013;

vector<int>g[mod];

int hashFind (int x){
  for (int u : g[x % mod]){
    if (u == x){
      return true;
    }
  }
  return false;
}

void hashAdd (int x){
  g[x % mod].push_back(x);
}

void hashErase (int x){
  vector<int>v;
  for (int u : g[x % mod]){
    if (u != x){
      v.push_back(u);
    }
  }
  g[x % mod].clear();
  for (int u : v){
    g[x % mod].push_back(u);
  }
}

int main(){
  int q; fin >> q;
  while (q--){
    int op, x; fin >> op >> x;
    if (op == 1){
      if (hashFind(x) == false){
        hashAdd(x);
      }
    }
    if (op == 2){
      if (hashFind(x) == true){
        hashErase(x);
      }
    }
    if (op == 3){
      fout << hashFind(x) << '\n';
    }
  }
}