传送门
我们按x排序 , 如果被包涵就直接剔除这个点
显然取一段连续的是最优的 , 因此定义f[i] 表示1--i 的最小价值
斜率优化搞一波 , 树形结合来写
#include
#define N 50050
#define LL long long
using namespace std;
LL f[N],n,tot,Max,q[N];
struct Node{LL x,y;}a[N],b[N];
bool cmp(Node a,Node b){
if(a.x==b.x) return a.y=1;i--) if(b[i].y>Max){
a[++tot] = b[i]; Max = b[i].y;
} sort(a+1,a+tot+1,cmp);
// f[i] = min(f[j] + a[j+1].y*a[i].x)
// b -> f[i] , y -> f[j] , k -> -a[i].x , x -> a[j+1].y
int l=1,r=0; q[++r]=0;
for(int i=1;i<=tot;i++){
while(l= -a[i].x) l++;
f[i] = f[q[l]] + a[q[l]+1].y * a[i].x;
while(l= K(q[r-1],q[r])) r--;
q[++r] = i;
} printf("%lld",f[tot]); return 0;
}