zoukankan      html  css  js  c++  java
  • bzoj 3437: 小P的牧场

    23333,随便推

     1 #include <bits/stdc++.h>
     2 #define LL long long
     3 #define lowbit(x) x&(-x)
     4 #define inf 0x3f3f3f3f
     5 #define eps 1e-5
     6 #define N 1000005
     7 using namespace std;
     8 inline LL ra()
     9 {
    10     LL x=0,f=1; char ch=getchar();
    11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    13     return x*f;
    14 }
    15 LL B[N],sum[N],a[N],b[N],f[N];
    16 int n,q[N];
    17 double slope(int j, int k)
    18 {
    19     return (f[j]-f[k]-sum[k]+sum[j])/(double)(B[j]-B[k]);
    20 }
    21 int main()
    22 {
    23     n=ra();
    24     for (int i=1; i<=n; i++) a[i]=ra();
    25     for (int i=1; i<=n; i++) b[i]=ra();
    26     for (int i=1; i<=n; i++) B[i]=B[i-1]+b[i];
    27     for (int i=1; i<=n; i++) sum[i]=sum[i-1]+(LL)b[i]*i;
    28     int l=0,r=0;
    29     for (int i=1; i<=n; i++)
    30     {
    31         while (l<r && slope(q[l+1],q[l])<i) l++;
    32         int t=q[l];
    33         f[i]=f[t]+a[i]+(LL)i*(B[i]-B[t])-sum[i]+sum[t];
    34         while (l<r && slope(i,q[r])<slope(q[r],q[r-1])) r--;
    35         q[++r]=i;
    36     }
    37     cout<<f[n];
    38     return 0;
    39 }
  • 相关阅读:
    word编号变黑块
    恢复未保存的word
    协方差分析
    SAS字体变大
    可变区组长度--区组随机
    adv and disadv of oncology clinical trial endpoints
    非劣效试验界值确定
    Computer Science
    Compuer Science
    随笔
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6544990.html
Copyright © 2011-2022 走看看