Cod sursa(job #2107539)

Utilizator Iulia25Hosu Iulia Iulia25 Data 17 ianuarie 2018 15:09:33
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <unordered_map>

using namespace std;

unordered_map <int, int> a;

int n, i, op, x;

const int Lim = 10000000;
int u =  Lim - 1;
char s[Lim];

void Next () {

    if (++u == Lim)
        std::fread(s, 1, Lim, stdin), u = 0;
}

void Get (int &x) {

    for (; s[u] < '0' || s[u] > '9'; Next());
    for (x = 0; s[u] >= '0' && s[u] <= '9'; Next())
		   x = x * 10 + s[u] - '0';

}

int main()  {
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
  Get(n);
  for (i = 1; i <= n; ++i)  {
    Get(op); Get(x);
    if (op == 1) ++a[x];
    else if (op == 2) {
      if (a[x])
        --a[x];
    }
    else if (a[x]) cout << 1 << '\n';
    else cout << 0 << '\n';
  }
}