#include
<
stdio.h
>
#define
?MAX?1000000
int
?heap[MAX];
class
?MIN_HEAP

{
public
:
?
int
?len;
?
int
?del_min(
int
?p);
?
int
?insert(
int
?x);
}
;

int
?MIN_HEAP::del_min(
int
?p)
{
?
int
?q
=
p
<<
1
,a
=
heap[p]
=
heap[len];
?heap[len
--
]
=
0
;

?
while
(q
<=
len)
{
??
if
(q
<
len
&&
heap[q
+
1
]
<
heap[q])q
++
;
??
if
(heap[q]
>=
a)
break
;
??heap[p]
=
heap[q];
??p
=
q;
??q
=
p
<<
1
;
?}
?heap[p]
=
a;
?
return
?len;
}
int
?MIN_HEAP::insert(
int
?x)
{
?heap[
++
len]
=
x;
?
int
?p
=
len;
?
int
?q
=
p
>>
1
,a
=
x;

?
while
(q
&&
a
<
heap[q])
{
??heap[p]
=
heap[q];p
=
q;q
=
p
>>
1
;
?}
?heap[?p]
=
a;
?
return
?len;
}
int
?main()

{
?
int
?n,i,j,x;
?MIN_HEAP?min_heap;
?scanf(
"
%d
"
,
&
n);
?
for
(i
=
1
;i
<=
n;i
++
)scanf(
"
%d
"
,heap
+
i);
?min_heap.len
=
n;?

?
while
(scanf(
"
%d
"
,
&
j))
{

??
if
(j
>
0
)
{
???scanf(
"
%d
"
,
&
x);
???min_heap.insert(x);
??}
??
else
{
???min_heap.del_min(
0
);
??}
??
for
(i
=
1
;i
<=
min_heap.len;i
++
)
???printf(
"
%d?
"
,heap[i]);
??printf(
"
\n
"
);
?}
?
return
?
0
;
}
看了那么久終于看完了,唉~真不知道該開心還是難過,看了又忘,先貼著有時間多看兩下5555555