```#include [HTML_REMOVED]
using namespace std;
const int N = 100010;
int heap[N];
int ph[N],hp[N];
int n,cnt;
int idx;
void heap_swap(int u,int v)
{
swap(ph[hp[u]],ph[hp[v]]);
swap(hp[u],hp[v]);
swap(heap[u],heap[v]);
}
void down(int u)
{
int t = u;
if (u2<=cnt && heap[u2]<heap[t]) t=u2;
if (u2+1<=cnt && heap[u2+1] <heap[t]) t=u2+1;
if (t!=u)
{
heap_swap(t,u);
down(t);
}
}
void up(int u)
{
while (u/2>=1 && heap[u/2] > heap[u])
{
heap_swap(u,u/2);
u>>=1;
}
}
int main()
{
scanf(“%d”,&n);
while (n–)
{
char op[5];
scanf(“%s”,op);
if (op[0]==’I’)
{
int x;
scanf(“%d”,&x);
heap[cnt]=x;
idx;
ph[idx]=cnt;
hp[cnt]=idx;
up(cnt);
}
else if (op[0]==’P’)
{
cout<<heap[1]<<endl;
}
else if (op[0]==’D’ && op[1]==’M’)
{
heap_swap(1,cnt);
cnt–;
down(1);
}
else if (op[0]==’D’)
{
int k;
scanf(“%d”,&k);
// swap不会改变数组下标,down、up参数是下标,要调整的是交换后cnt对应的值的下标。如果用ph[k]则下标是cnt
k = ph[k];
heap_swap(k,cnt);
cnt–;
down(k);
up(k);
}
else
{
int k,x;
scanf(“%d%d”,&k,&x);
k=ph[k];
heap[k]=x;
down(k);
up(k);
}
}
return 0;
}
```