Pagini recente » Cod sursa (job #2879550) | Cod sursa (job #913695) | Cod sursa (job #2507505) | Cod sursa (job #2303242) | Cod sursa (job #514478)
Cod sursa(job #514478)
# include <fstream>
# define MAX 200100
using namespace std;
ifstream f ("heapuri.in");
ofstream g ("heapuri.out");
int n;
int elem[MAX], v[MAX];
inline int dad (int son){
return son >> 1;
}
inline int son1 (int dad){
return dad << 1;
}
inline int son2 (int dad){
return (dad << 1) + 1;
}
void HEAP (int poz){
for (;;){
int x = dad (poz), y = son2 (x);
if (v[x] >= v[poz] && v[poz] <= v[y] && x > 0 && y > 0){//daca v[x] poate fi tata
int aux = v[x];
v[x] = v[poz];
v[poz] = aux;
poz = x;
}
else{
break ;//nu mai poate inainta
}
}
}
void HEAP2 (int poz){
for (;;){
int x = son1 (poz), y = son2 (poz);
if (v[x] <= v[y] && x <= v[0]){
int aux = v[x];
v[x] = v[poz];
v[poz] = aux;
poz = x;
}
else
if (v[x] > v[y] && y <= v[0]){
int aux = v[y];
v[y] = v[poz];
v[poz] = aux;
poz = y;
}
else break ;
}
}
int main (){
f >> n;
for (int i = 1; i <= n; ++i) v[i] = 2000000000;
for (int i = 1; i <= n; ++i){
int cit, nr;
f >> cit;
if (cit == 1){
int var;
f >> nr;
v[++v[0]] = nr;
HEAP (v[0]);
elem[++elem[0]] = nr;
}
else
if (cit == 2){
f >> nr;
int pozitie = elem[nr], pozlast;
for (int j = 1; j <= n; ++j)
if (v[j] == pozitie){
pozlast = j;
break ;
}
v[pozlast] = 2000000000;
HEAP2 (pozlast);
}
else g << v[1] << '\n';
}
g.close ();
return 0;
}