pro

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 101000;

struct Node{
    double x,y;
    Node(){}
    Node(double x,double y):x(x),y(y){}
}nod[N];

Node operator + (const Node &a,const Node &b){
    return Node(a.x+b.x,a.y+b.y);
}
Node operator - (const Node &a,const Node &b){
    return Node(a.x-b.x,a.y-b.y);
}

double dot(const Node &a,const Node &b){
    return a.x*b.x+a.y*b.y;
}
double cross(const Node &a,const Node &b){
    return a.x*b.y-a.y*b.x;
}

ll ans,n,m,a[N],b[N],pre[N],num[N];
bool check(int,int);
bool check(Node&,Node&,Node&);
int main(){
    
    scanf("%lld%lld",&n,&m);
    for (int i = 1;i <= n;i++) scanf("%lld",&a[i]);
    for (int i = 1;i <= m;i++) scanf("%lld",&b[i]);
    
    for (int i = 1;i <= n;i++) pre[i] = pre[i-1]+a[i];
    
    int t = 1,w = 2;
    
    nod[1] = Node(pre[1],pre[1]-a[1]);num[1] = 1;
    nod[2] = Node(pre[2],pre[2]-a[2]);num[2] = 2;
    
    
    for (int i = 3;i <= n;i++){
        Node c = Node(pre[i],pre[i]-a[i]);
        while (t < w && check(nod[w-1],nod[w],c)) w--;
        nod[++w] = c;num[w] = i;
    }
    
    for (int i = 2;i <= m;i++){
        int l = t,r = w,mid = l + r >> 1;
        while (l < r){
            if (check(mid,i)) l = mid + 1;else r = mid; 
            mid = l + r >> 1;
        }
        ans += pre[num[l]]*b[i-1]-pre[num[l]-1]*b[i];
    }
    ans += pre[n]*b[m];
    printf("%lld\n",ans);
    return 0;
}
bool check(int x,int y){
//    return (nod[x].y-nod[x+1].y)/(nod[x].x-nod[x+1].x)<b[y-1]/b[y];
    return (nod[x+1].y-nod[x].y)*b[y]<(nod[x+1].x-nod[x].x)*b[y-1];
}
bool check(Node& x,Node& y,Node& z){
    return cross(y-x,z-x) <= 0;
}

 

转载于:https://www.cnblogs.com/victbr/p/6526839.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值