Pagini recente » Cod sursa (job #2663614) | Cod sursa (job #2963631) | Cod sursa (job #2141130) | Cod sursa (job #2661092) | Cod sursa (job #1792049)
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct numar{
int nr, index;
};
bool cmp(numar& a, numar& b)
{
return (a.nr>b.nr);
}
bool sters[100000001]={0};
vector <numar> v;
char buff[200000];int pos=0;
FILE*f=freopen("heapuri.in","r",stdin);
FILE*g=freopen("heapuri.out","w",stdout);
inline void read(int &nr){
while(buff[pos] < '0' || buff[pos] > '9')if(++pos == 200000) fread(buff, 1, 200000, stdin), pos = 0;
nr = 0;
while('0' <= buff[pos] && buff[pos] <= '9') {nr = nr * 10 + buff[pos] - '0';if(++pos == 200000) fread(buff, 1, 200000, stdin), pos = 0;}
}
int main()
{
int i, n, cr, nr, lg=0;
numar numar;
read(n);
for(i=1; i<=n; i++)
{
read(cr);
if(cr==1)
{
read(nr);
numar.nr = nr;
numar.index = ++lg;
v.push_back(numar);
push_heap(v.begin(), v.end(), cmp);
}
if(cr==2)
{
read(nr);
sters[nr] = true;
}
if(cr==3)
{
while(sters[v.front().index])
{
pop_heap(v.begin(),v.end(),cmp);
v.pop_back();
}
printf("%d\n", v.front());
}
}
}