Pagini recente » Cod sursa (job #2927862) | Cod sursa (job #2760546) | Cod sursa (job #2230995) | Cod sursa (job #170061) | Cod sursa (job #2811528)
#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;
}