Cod sursa(job #2811528)

Utilizator CristeaCristianCristea Cristian CristeaCristian Data 2 decembrie 2021 14:53:29
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <vector>

using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
vector <int> heap(1, 0), ind(1, 0);
const int NMAX = 200005;
int poz[NMAX];
bool empty()
{
    return (heap.size() == 1);
}
void insert(int x)
{
    heap.push_back(x);
    int pos = heap.size() - 1;
    ind.push_back(pos);
    poz[pos] = pos;
    while(pos / 2 > 1)
    {
        if(heap[pos] < heap[pos / 2])
        {
            swap(ind[pos], ind[poz[pos/2]]);
            swap(poz[pos], poz[pos/2]);
            swap(heap[pos], heap[pos / 2]);
        }
        else
            break;
        pos = pos / 2;
    }
}
int main()
{
    int m, i, op, x;
    fin >> m;
    while(m--)
    {
        fin >> op;
        if(op == 1)
        {
            fin >> x;
            insert(x);
        }
        else if(op == 2)
        {
            fin >> x;
            //erase(x);
        }
        else
        {
            //fout << top() << '\n';
        }
    }
    return 0;
}