#include<cstdio>
#include<iostream>
#include<algorithm>
#define max(x,y) (x)>(y)?(x):(y)
using namespace std;
const int MAXN=1e5;
int n,a[MAXN+5],w,p,cur,s[MAXN+5];
inline int read()
{
register int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
void swap(int &x,int &y)
{
int t=x;
x=y;
y=t;
}
struct BIG_HEAP
{
int len;
int a[MAXN+5];
int top()
{
return a[1];
}
void put(int x)
{
++len;
a[len]=x;
int cur=len,fa=cur>>1;
while(fa>=1)
{
if(a[fa]<a[cur]) swap(a[fa],a[cur]);
else return;
cur=fa;
fa=cur>>1;
}
}
void pop()
{
a[1]=a[len];
--len;
int cur=1,son=cur*2;
while(son<=len)
{
if(a[(son|1)]>a[son]&&(son|1)<=len) son|=1;
if(a[son]>a[cur]) swap(a[son],a[cur]);
else return;
cur=son;
son=cur*2;
}
}
}bh;
struct SMALL_HEAP
{
int len;
int a[MAXN+5];
int top()
{
return a[1];
}
void put(int x)
{
++len;
a[len]=x;
int cur=len,fa=cur>>1;
while(fa>=1)
{
if(a[fa]>a[cur]) swap(a[fa],a[cur]);
else return;
cur=fa;
fa=cur>>1;
}
}
void pop()
{
a[1]=a[len];
--len;
int cur=1,son=cur*2;
while(son<=len)
{
if(a[(son|1)]<a[son]&&(son|1)<=len) son|=1;
if(a[son]<a[cur]) swap(a[son],a[cur]);
else return;
cur=son;
son=cur*2;
}
}
}sh;
inline void r()
{
n=read(),w=read();
for(int i=1;i<=n;i++)
a[i]=read();
}
int rank()
{
return max(1,(p*w/100));
}
inline void solve()
{
int sizes=0,sizeb=0;
for(p=1;p<=n;p++)
{
sizes=rank();
sizeb=n-rank();
if(a[p]>bh.top()) sh.put(a[p]);
else bh.put(a[p]);
if(sh.len==sizes)
{
//printf("sh.len=%d,bh.len=%d,p=%d\n",sh.len,bh.len,p);
printf("%d ",sh.top());
continue;
}
if(sh.len<sizes)
{
sh.put(bh.top());
bh.pop();
}
else
{
bh.put(sh.top());
sh.pop();
}
//printf("sh.len=%d,bh.len=%d,p=%d\n",sh.len,bh.len,p);
printf("%d ",sh.top());
}
}
int main()
{
//freopen("live.in","r",stdin);
//freopen("live.out","w",stdout);
r();
solve();
return 0;
}
或将成为唯一手写堆的勇士
int rank()
{
return max(1,(p*w/100));
}
我写了个这个函数结果luogu编译提示
/tmp/compiler_2fnub2df/src:117:9: 错误:对‘rank’的引用有歧义
sizes=rank();
……
/tmp/compiler_2fnub2df/src:118:11: 错误:对‘rank’的引用有歧义
sizeb=n-rank();
oitiku上AC,luogu上CE,萌新现在害怕极了,我不想爆零啊5555555555555