Cod sursa(job #1224059)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 29 august 2014 15:55:32
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.77 kb
#include <cstdio>
#include <cstring>
#include <cassert>

#include <algorithm>
#include <vector>
#include <unordered_set>

using namespace std;

class Reader {
  public:
    Reader(FILE *_stream, const int _size = (1 << 16)):
      size(_size),
      pointer(0),
      buffer(new char[_size]),
      stream(_stream) {
        assert(fread(buffer, 1, size, stream) != 0);
    }

    template<class IntType>
    IntType NextInt() {
        IntType value = 0;
        bool negative = false;
        while ((Current() < '0' || Current() > '9') && Current() != '-')
            NextPosition();
        if (Current() == '-') {
            negative = true;
            NextPosition();
        }
        while(Current() >= '0' && Current() <= '9') {
            value = value * 10 + Current() - '0';
            NextPosition();
        }
        if (negative)
            value = -value;
        return value;
    }

    Reader &operator>>(int &value) {
        value = NextInt<int>();
        return *this;
    }

  private:
    int size, pointer;
    char *buffer;
    FILE *stream;

    char Current() const {
        return buffer[pointer];
    }

    void NextPosition() {
        if(++pointer == size) {
            assert(fread(buffer, 1, size, stream) != 0);
            pointer = 0;
        }
    }
};

unordered_set<int> H;

int main() {
    assert(freopen("hashuri.in", "r", stdin));
    assert(freopen("hashuri.out", "w", stdout));
    Reader in = Reader(stdin);
    int q; in >> q;
    for (; q > 0; --q) {
        int type, value;
        in >> type >> value;
        if (type == 1)
            H.insert(value);
        if (type == 2)
            H.erase(value);
        if (type == 3)
            printf("%d\n", H.find(value) != H.end());
    }
    return 0;
}