1010

思路:

  斜率优化DP;

  跪烂大佬

代码:

#include <bits/stdc++.h>
using namespace std;
#define maxn 50005
#define ll long long
ll que[maxn],sum[maxn],dp[maxn],n,l,ai[maxn],a;
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
ll G(ll now)
{
return sum[now]+now;
}
ll Y(ll x,ll y)
{
return dp[x]+pow(G(x)+a,)-dp[y]-pow(G(y)+a,);
}
ll X(ll x,ll y)
{
return *(G(x)-G(y));
}
int main()
{
in(n),in(l),a=l+;ll h=,tail=;
for(ll i=;i<=n;i++) in(ai[i]),sum[i]=sum[i-]+ai[i];
for(ll i=;i<=n;i++)
{
while(h<tail&&Y(que[h+],que[h])<=G(i)*X(que[h+],que[h])) ++h;
dp[i]=dp[que[h]]+(G(i)-G(que[h])-a)*(G(i)-G(que[h])-a);
while(h<tail&&Y(i,que[tail])*X(que[tail],que[tail-])<=Y(que[tail],que[tail-])*X(i,que[tail])) --tail;
que[++tail]=i;
}
cout<<dp[n];
return ;
}

AC日记——[HNOI2008]玩具装箱toy bzoj 1010的更多相关文章

  1. 【BZOJ 1010】 [HNOI2008]玩具装箱toy (斜率优化)

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9330  Solved: 3739 Descriptio ...

  2. bzoj 1010 [HNOI2008]玩具装箱toy(DP的斜率优化)

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 7874  Solved: 3047[Submit][St ...

  3. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  4. BZOJ 1010: [HNOI2008]玩具装箱toy 斜率优化DP

    1010: [HNOI2008]玩具装箱toy Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再 ...

  5. BZOJ 1010 [HNOI2008]玩具装箱toy

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 7184  Solved: 2724[Submit][St ...

  6. Bzoj 1010: [HNOI2008]玩具装箱toy(斜率优化)

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MB Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定 ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy(DP+斜率优化)

    [HNOI2008]玩具装箱toy Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊 ...

  8. 1010: [HNOI2008]玩具装箱toy(斜率优化)

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 12280  Solved: 5277[Submit][S ...

  9. 【bzoj1010】[HNOI2008]玩具装箱toy

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9281  Solved: 3719[Submit][St ...

随机推荐

  1. Codeforces Round #331 (Div. 2) A

    A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. python升级引发的问题总结

    http://www.cnblogs.com/ajianbeyourself/p/4214398.html http://www.cnblogs.com/hanggegege/p/6993003.ht ...

  3. (转)python编码问题

    时不时总是会碰到令人头疼的编码问题,这里推荐一篇决定好文,需反复诵读之: http://www.cnblogs.com/huxi/archive/2010/12/05/1897271.html . . ...

  4. ASP.NET和ASP的区别是什么

    分析: ASP与ASP.NET是Microsoft公司在Web应用程序开发上的两项重要技术. ASP与ASP.NET区别如下: (1)开发语言不同:ASP的开发语言仅局限于使用non-type脚本语言 ...

  5. easyui datagrid 的数据加载Json数据

    var obj = {'total':100,'rows':[{id:'1',name:'一'},{id:'2',name:'二'}]}; $('#tt').datagrid('loadData',o ...

  6. js中的true和false

    1.false undefined.NaN.0.null和空字符串''均被视为false 2.true 除上述以外的其它情况一律被视作true

  7. perl中的默认变量与Z/map介绍

    use v6; =begin pod @*ARGS 命令行参数, 不含脚本名 $*PROGRAM-NAME:当前运行脚本的相对路径 $*PROGRAM:当前运行脚本的文件名称 $*CWD:当前工作路径 ...

  8. Android 6.0 Marshmallow root 方法

    android 6.0 已经推出 release 版本了, nexus 5,6,7,9 都放了官方镜像, 本篇文章使用 nexus 6 安装最新的 android 6.0 并进行root step 1 ...

  9. notifier chain — 内核通知链【转】

    转自:http://blog.csdn.net/g_salamander/article/details/8081724 大多数内核子系统都是相互独立的,因此某个子系统可能对其它子系统产生的事件感兴趣 ...

  10. Development tools[重点]

    Development tools yum groupinfo "Development tools" Loaded plugins: product-id, security, ...