Cod sursa(job #1021437)

Utilizator razvan9310FMI - Razvan Damachi razvan9310 Data 3 noiembrie 2013 20:16:04
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
#include <unordered_map>
#define mod 666013
using namespace std;

unsigned int hashFunction(unsigned int x) {
  x = ((x >> 16) ^ x) * 0x45d9f3b;
  x = ((x >> 16) ^ x) * 0x45d9f3b;
  x = ((x >> 16) ^ x);
  return x;
}

int main()
{
    int N;
    ifstream in("hashuri.in");
    ofstream out("hashuri.out");
    unordered_map<int, int> hash;
    in>>N;
    for (int i = 0; i < N; ++i) {
      int c, x;
      in>>c>>x;
      switch(c) {
        case 1: hash.insert(make_pair(hashFunction(x), x)); break;
        case 2: hash.erase(hashFunction(x)); break;
        case 3: out<<(hash.find(hashFunction(x)) != hash.end())<<"\n"; break;
        default: return -1;
      }
    }
    in.close();
    out.close();

    return 0;
}