Cod sursa(job #1124803)

Utilizator toranagahVlad Badelita toranagah Data 26 februarie 2014 13:49:48
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <algorithm>
#include <fstream>
#include <iostream>
#include <unordered_set>
using namespace std;

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

struct MyHasher {
  bool operator()(int val) const {
    return (val & ((1 << 20) - 1));
  }
};

int main() {
  unordered_set<int, MyHasher> h;
  int m;
  fin >> m;

  for (int i = 1, op, val; i <= m; i += 1) {
    fin >> op >> val;
    if (op == 1) {
      h.insert(val);
    } else if (op == 2) {
      h.erase(val);
    } else {
      fout << h.count(val) << '\n';
    }
  }
  return 0;
}