void swap(int &x,int &y){int z=x;x=y;y=z;}
struct small_root_heap{
int heap[M],top;
void insert(int x){heap[++top]=x;int t=top;while(t>1&&heap[t]<heap[t>>1])swap(heap[t],heap[t>>1]),t>>=1;}
void pop()
{
int t=2;
heap[1]=heap[top];heap[top--]=0;
while(t<=top)
{
if(heap[t]>heap[t+1]&&t<top)t++;
if(heap[t]<heap[t>>1])swap(heap[t],heap[t>>1]),t<<=1;
else break;
}
}
};
struct big_root_heap{
int heap[M],top;
void insert(int x){heap[++top]=x;int t=top;while(t>1&&heap[t]>heap[t>>1])swap(heap[t],heap[t>>1]),t>>=1;}
void pop()
{
int t=2;
heap[1]=heap[top];heap[top--]=0;
while(t<=top)
{
if(heap[t]<heap[t+1]&&t<top)t++;
if(heap[t]>heap[t>>1])swap(heap[t],heap[t>>1]),t<<=1;
else break;
}
}
};
堆模板
原创
©著作权归作者所有:来自51CTO博客作者popoqqq的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:单调队列模板
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
记一次JVM堆外内存泄漏问题
一次由JVM堆外内存泄漏引发的POD重启问题的解决之路。
JVM 内存泄漏 堆外内存 POD重启 -
【模板】左偏树(可并堆)
左偏树模板
左偏树模板 左偏树 #define i++ #include