Cod sursa(job #2720050)

Utilizator stefanlupoi1Lupoi Stefan stefanlupoi1 Data 10 martie 2021 15:48:39
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.39 kb
#include <stdio.h>
#include <ctype.h>
#include <unordered_map>
#include <fstream>

using namespace std;

unordered_map <int, bool> m;

class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;

	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}

public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}

	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}

	InParser& operator >> (long long &n) {
		char c;
		n = 0;
		while (!isdigit(c = read_ch()) && c != '-');
		long long sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};


int main()
{
    InParser in("hashuri.in");
    ofstream out("hashuri.out");
    int n, x, op;
    in >> n;
    while(n--){
        in >> op >> x;
        if(op == 1){
            m[x] = true;
        }
        else if(op == 2){
            m[x] = false;
        }
        else{
            out << m[x] << '\n';
        }
    }
    return 0;
}