Cod sursa(job #794222)

Utilizator Theorytheo .c Theory Data 5 octombrie 2012 23:07:42
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 2.06 kb
/*
#include<fstream>
#define nmax 100000
using namespace std;
ifstream fin("heap.in");
ofstream fout("heap.out");

int N, H[nmax] ,L,poz;
void schimba(int &a, int &b)
{

    int aux = a;
    a = b;
    b = aux;
}
void insert(int x)
{

    ++L;
    H[L] = x;
    poz = L;
    while(poz/2 && H[poz] > H[poz/2])
    {

        schimba(H[poz],H[poz/2]);

        poz = poz / 2;

    }
}

void swift(int k)
{
    int sc = 0;
    while(sc != k)
    {
        sc = k;
        if(H[k] < H[k * 2] && k * 2 <=L )
            sc = k * 2;

        if(H[sc] <  H[k * 2 + 1] && k * 2 + 1 <=L)
            sc = 2 *k + 1;
        swap(H[k], H[sc]);
    }
}
void citire()
{
    int a;
    fin >>N;
    for(int i = 1; i <= N;i++)
    {
        fin >> a;
        H[i] = a;
        //insert(a);
    }

}
inline void afis(int i)
{
    fout <<"Fiii lui " << H[i] <<" sunt "<< H[i + i] <<" si " << H[i + i + 1]<<'\n';

}
int main()
{
    citire();
    L = N;
    for(int i = N; i > 0 ;--i)
        swift(i);

    int t = 0 ,nivel = 1;
    for(int i = 1; i <= L && t <= L ;i++){
         for(int j = 1; j <= nivel && t<=L ;++j)
            fout << H[++t]<<"    ";
        nivel *= 2;
        fout <<'\n';
    }



    fin.close();
    return 0;

}

*/
#include<fstream>
#include<set>
#define nmax 200008
using namespace std;

ifstream fin("heapuri.in");
ofstream fout("heapuri.out");

int N, op, type, x, Z[nmax], nr;

multiset<int> V;
//multiset<int>::iterator it;

int main()
{
    fin >> N;
    for(int i = 1; i <= N; i++ )
    {
        fin >>type;
        switch(type){
         case 1:
         {
             fin >> x;
             Z[++nr] = x;

             V.insert(x);
             break;
         }
         case 2:
         {
             fin >> x;
             V.erase(V.find(Z[x]));
             break;
         }
         default :{

             //it = V.begin();
             fout << *V.begin() <<'\n';
             break;
         }
        }

    }
    fin.close();
    return 0;
}