Cod sursa(job #2326932)

Utilizator ApostolIlieDanielApostol Daniel ApostolIlieDaniel Data 24 ianuarie 2019 11:44:52
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6;

vector <int> v[MAXN];

void add (int x) {
  v[x % MAXN].push_back (x);
}

void erase (int x) {
  int i = 0;
  for (auto y : v[x % MAXN]) {
    if (y == x) {
      swap (v[x % MAXN][i], v[x % MAXN][v[x % MAXN].size () - 1]);
      v[x % MAXN].pop_back ();
      return;
    }
    i++;
  }
}

bool find (int x) {
  for (auto y : v[x % MAXN])
    if (y == x)
      return 1;
  return 0;
}

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

  scanf ("%d", &n);

  while (n--) {
    scanf ("%d%d", &tip, &x);
    if (tip == 1)
      add (x);
    if (tip == 2)
      erase (x);
    if (tip == 3)
      printf ("%d\n", find (x));
  }

  return 0;
}