Cod sursa(job #2897120)

Utilizator vladsipunct5555Butnrau Vlad vladsipunct5555 Data 2 mai 2022 15:58:22
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.54 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;
ofstream out ("heapuri.out");
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;
	}
};
main ()
{
    int q;
    InParser in("heapuri.in");
    in >> q;
    multiset <int> seti;
    vector <int> v;
    for (int i = 1;i<=q;++i)
    {
        int type;
        in >> type;
        if (type == 1)
        {
            int a;
            in >> a;
            v.push_back(a);
            seti.insert(a);
        }
        else if (type == 2)
        {
            int k;
            in >> k;
            seti.erase(seti.find(v[k - 1]));
        }
        else
        out << *(seti.begin()) << '\n';
    }
    return 0;
}