Cod sursa(job #1021399)

Utilizator nimeniaPaul Grigoras nimenia Data 3 noiembrie 2013 19:36:16
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <algorithm>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <set>

using namespace std;

const int md = 666013;

vector<int> vects[md];

inline int _hash (int val) {
  return val % md;
}

inline void add(int val) {
  int index = _hash(val);
  vects[index].push_back(val);
}

inline void remove(int val) {
  int index = _hash(val);
  vector<int> &v = vects[index];
  vector<int>::iterator it = find(v.begin(), v.end(), val);
  if (it != v.end())
    v.erase(it);
}

inline int find(int val) {
  int index = _hash(val);
  vector<int> &v = vects[index];
  return find(v.begin(), v.end(), val) == v.end() ? 0 : 1;
}

ifstream f("hashuri.in");
ofstream g("hashuri.out");

int main(int argc, char *argv[])
{

  int n;
  f >> n;

  for (int i = 0; i < n; i++) {
    int op, val;
    f >> op >> val;

    switch (op) {
    case 1: add(val); break;
    case 2: remove(val); break;
    case 3: g << find(val) << endl; break;
    }
  }

  return 0;
}