发现挺多面经里有提到。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int a[maxn];
void Sort(int l,int r){
if(l>=r) return ;
int i=l,j=r;
int x=a[i];
while(i<j){
while(i<j&&a[j]>=x) --j;
if(i<j) a[i++]=a[j];
while(i<j&&a[i]<=x) ++i;
if(i<j) a[j--]=a[i];
}
a[i]=x;
Sort(l,i-1);
Sort(i+1,r);
}
struct HEAP{
int heap[maxn<<2|1];//小根堆;
int num;
void up(int p){
while(p>1)
if(heap[p]<heap[p/2]){
swap(heap[p],heap[p/2]);
p/=2;
}
else break;
}
void down(int p){
int s=p*2;
while(s<=num){
if(heap[s+1]<heap[s]) ++s;
if(heap[s]<heap[p]){
swap(heap[s],heap[p]);
p=s;s=p*2;
}
else break;
}
}
void insert(int val){
heap[++num]=val;
up(num);
}
void pop(){
heap[1]=heap[num--];
down(1);
}
int top(){
return heap[1];
}
bool isempty(){
return num==0;
}
};
int main(){
return 0;
}