Cod sursa(job #1021402)

Utilizator nimeniaPaul Grigoras nimenia Data 3 noiembrie 2013 19:39:43
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 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;
  freopen("hashuri.in", "r", stdin);
  freopen("hashuri.out", "w", stdout);

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int op, val;
    scanf("%d %d", &op, &val);

    switch (op) {
    case 1: add(val); break;
    case 2: remove(val); break;
    case 3: printf("%d\n", find(val)); break;
    }
  }

  return 0;
}