Cod sursa(job #2223925)

Utilizator vladm98Munteanu Vlad vladm98 Data 22 iulie 2018 12:05:12
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.35 kb
#include <bits/stdc++.h>

using namespace std;

class Reader {
public:
    Reader(const string& filename):
            m_stream(filename),
            m_pos(kBufferSize - 1),
            m_buffer(new char[kBufferSize]) {
        next();
    }

    Reader& operator>>(int& value) {
        value = 0;
        while (current() < '0' || current() > '9')
            next();
        while (current() >= '0' && current() <= '9') {
            value = value * 10 + current() - '0';
            next();
        }
        return *this;
    }

private:
    const int kBufferSize = 32768;

    char current() {
        return m_buffer[m_pos];
    }

    void next() {
        if (!(++m_pos != kBufferSize)) {
            m_stream.read(m_buffer.get(), kBufferSize);
            m_pos = 0;
        }
    }

    ifstream m_stream;
    int m_pos;
    unique_ptr<char[]> m_buffer;
};

set <int> s;

int main() {
    Reader fin ("hashuri.in");
    ofstream fout ("hashuri.out");
    int n;
    fin >> n;
    for (int i = 1; i <= n; ++i) {
        int tip, x;
        fin >> tip >> x;
        if (tip == 1) {
            s.insert(x);
        }
        if (tip == 2) {
            s.erase(x);
        }
        if (tip == 3) {
            if (s.find(x) != s.end()) {
                cout << 1 << '\n';
            } else {
                cout << 0 << '\n';
            }
        }
    }
    return 0;
}