Cod sursa(job #642803)

Utilizator bmaticanBogdan-Alexandru Matican bmatican Data 2 decembrie 2011 12:01:18
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>
#include <list>

using namespace std;

const int MAXIM = 666667;
list<int> h[MAXIM];

list<int>::iterator find(int x) {
  int pos = x % MAXIM;
  for (list<int>::iterator it = h[pos].begin(); it != h[pos].end(); ++it) {
    if (*it == x) {
      return it;
    }
  }
  return h[pos].end();
}

void solve() {
  int n;
  scanf("%d", &n);
  int t;
  int x;
  while (n--) {
    scanf("%d %d", &t, &x);
    int pos = x % MAXIM;
    if (1 == t) {
      if (find(x) == h[pos].end()) {
        h[pos].push_front(x);
      }
    } else if (2 == t) {
      list<int>::iterator it = find(x);
      if (it != h[pos].end()) {
        h[pos].erase(it);
      }
    } else if (3 == t) {
      printf("%d\n", (find(x) != h[pos].end()));
    }
  }
}

int main() {
  freopen("hashuri.in", "r", stdin);
  freopen("hashuri.out", "w", stdout);

  solve();
  return 0;
}