分析
https://www.luogu.org/blog/22112/solution-p5155
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node {
int x,y;
};
node d[100100],a;
inline node operator - (node x,node y){return (node){x.x-y.x,x.y-y.y};}
inline int operator * (node x,node y){return x.x*y.y-x.y*y.x;}
signed main(){
int n,m=0,i,j,k;
scanf("%lld",&n);
for(i=1;i<=n+1;i++){
a.x=i;
if(i<=n)scanf("%lld",&a.y);
else a.y=0;
a.y*=100000;
while(m&&(a-d[m])*(d[m]-d[m-1])<=0)m--;
d[++m]=a;
}
for(i=1,j=0;i<=n;i++){
while(j<m&&d[j].x<i)j++;
if(d[j].x==i)printf("%lld
",d[j].y);
else printf("%lld
",((d[j].x-i)*d[j-1].y+
(i-d[j-1].x)*d[j].y)/(d[j].x-d[j-1].x));
}
return 0;
}