Pagini recente » Cod sursa (job #266369) | Cod sursa (job #2805338) | Cod sursa (job #1878913) | Cod sursa (job #1713686) | Cod sursa (job #2745959)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
const int intmax = 1<<30;
typedef pair<int,int> pii;
vector<pii> v;
vector<int> poz;
void Sift(int N, int i){
int son = 2*i+1;
while( son < N ){
if(son + 1 < N && v[son+1].first < v[son].first)
son++;
if(v[i].first <= v[son].first)
break;
swap(poz[v[i].second], poz[v[son].second]);
swap(v[i], v[son]);
i = son;
son = 2*i+1;
}
}
void Percolate(int N, int i){
int father = (i-1)/2;
while(father >= 0){
if(v[father].first <= v[i].first)
break;
swap(poz[v[i].second], poz[v[father].second]);
swap(v[i], v[father]);
i = father;
father = (i-1)/2;
}
}
void Add (int& m, int& ct){
int x;
fin >> x;
v.push_back({x,m});
poz.push_back(ct);
ct ++ ;
m++;
Percolate(m,m-1);
}
void Do(){
int n, t, x;
int ct = 0;
int m = 0;
vector<pii> tasks;
fin >> n;
for(int i = 0; i<n; ++i){
fin >> t;
if(t == 1){
Add(m, ct);
}
else if (t == 2){
fin >> x;
x--;
v[poz[x]].first = intmax;
Sift(m, poz[x]);
//m--;
}
else {
fout << v[0].first << "\n";
}
}
}
int main()
{
Do();
return 0;
}