Cod sursa(job #2747337)
| Utilizator | Data | 29 aprilie 2021 00:37:38 | |
|---|---|---|---|
| Problema | Heapuri | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 1.06 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
priority_queue <int, vector<int>, greater<int> > pq,deleted_pq;
unordered_map<int, int> umap;
int n,i,operatie,x,nr=0;
int main ()
{
f>>n;
for(i=0;i<n;i++)
{
f>>operatie;
if(operatie==1)
{
f>>x;
pq.push(x);
nr+=1;
umap[nr]=x;
}
else if(operatie==3)
{
g<<pq.top()<<'\n';
}
else if(operatie==2)
{
f>>x;
while(pq.empty()!=1){
if(pq.top()==umap[x])
{
pq.pop();
break;
}
else{
deleted_pq.push(pq.top());
pq.pop();
}
}
while(deleted_pq.empty()!=1)
{
pq.push(deleted_pq.top());
deleted_pq.pop();
}
}
}
return 0;
}
