【模板】斜率优化dp的常用模板

struct point{
    ll x,y;
    point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
    point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
};
ll cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}
point q[N]; 
int head,tail;
void pop(ll k){
    while(tail>head && q[head+1].y-q[head].y<=k*(q[head+1].x-q[head].x))
        head++;
}
void push(point k1){
    while(tail>head && cross(q[tail]-k1,q[tail-1]-k1)>=0)tail--;
    q[++tail]=k1;
}

 

posted on 2020-03-18 21:26  zsben  阅读(168)  评论(0编辑  收藏  举报

导航