/*小根堆*/ class Heap{ private : int num[1008] ; int N ; public : void push(int) ; int top() ; void pop() ; void up(int) ; void down(int) ; int empty_() ; Heap() ; }; Heap::Heap(){ N = 0 ; } int Heap::top(){ return num[1] ; } int Heap::empty_(){ return N < 1 ; } void Heap::down(int id){ int Lson = id<<1 ; int Rson = id<<1|1 ; int next = id ; if(Lson <= N && num[Lson] < num[next]) next = Lson ; if(Rson <= N && num[Rson] < num[next]) next = Rson ; if(next != id){ swap(num[id],num[next]) ; down(next) ; } } void Heap::up(int id){ int father = id>>1 ; if(father >=1 && num[id] < num[father]){ swap(num[id],num[father]) ; up(father) ; } } void Heap::pop(){ swap(num[N],num[1]) ; N-- ; down(1) ; } void Heap::push(int x){ num[++N] = x ; up(N) ; }