tle三个点的请进

P3378 【模板】堆

蒟蒻表示手打堆过的
by Whiteying @ 2017-11-07 20:37:37


优先队列是你的好伙伴
by moye到碗里来 @ 2017-11-07 20:51:06


有闲情记那个还不如用scanf和printf…… 再想快就读优啊……
by scp233 @ 2018-02-07 22:03:50


@[yzher](/space/show?uid=5889) 还是超时啊QAQ ```cpp #include <iostream> using namespace std; int n,f,x,t=0,a[1000005]; void heapadjust(int i,int n) { int lchild=i*2,rchild=2*i+1,max=i; if (i<=n/2) { if (lchild<=n && a[lchild]>a[max]) { max=lchild; } if (rchild<=n && a[rchild]>a[max]) { max=rchild; } if (max!=i) { swap(a[max],a[i]); heapadjust(max,n); } } } void buildheap(int n) { for (int i=n/2;i>=1;i--) { heapadjust(i,n); } } void heapsort(int n) { buildheap(n); for (int i=n;i>=1;i--) { swap(a[i],a[1]); heapadjust(1,i-1); } } int main() { ios::sync_with_stdio(false); cin>>n; for (int i=1;i<=n;i++) { cin>>f; if (f==1) { cin>>x; t++; a[t]=x; heapsort(t); } else if (f==2) { cout<<a[1]<<endl; } else { t--; for (int i=1;i<=t;i++) { a[i]=a[i+1]; } /*for (int i=1;i<=t;i++) { cout<<a[i]<<" "; }*/ //heapsort(t); } } return 0; } ```
by 许凉城 @ 2018-10-28 16:33:50


|