推出来式子然后斜率优化水过去就完事了

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#define inf 0x3f3f3f3f
#define LL long long int
using namespace std;
const int maxn=; inline LL rd(){
LL x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} int N;
LL co[maxn],sm[maxn],f[maxn],L;
int q[maxn],h,t; inline LL pw2(LL x){return x*x;} inline bool judge1(int j1,int j2,int i){
return f[j1]+pw2(j1+sm[j1])-f[j2]-pw2(j2+sm[j2])<(*i+*sm[i]-*L-)*(j1+sm[j1]-j2-sm[j2]);
}
inline bool judge2(int j1,int j2,int j3){
return (f[j1]+pw2(j1+sm[j1])-f[j2]-pw2(j2+sm[j2]))*(j2+sm[j2]-j3-sm[j3])<
(f[j2]+pw2(j2+sm[j2])-f[j3]-pw2(j3+sm[j3]))*(j1+sm[j1]-j2-sm[j2]);
} int main(){
int i,j,k;
N=rd();L=rd();
for(i=;i<=N;i++)co[i]=rd(),sm[i]=sm[i-]+co[i];
h=t=;q[]=;
for(i=;i<=N;i++){
while(h<t&&!judge1(q[h],q[h+],i)) h++;
f[i]=f[q[h]]+pw2(i-q[h]-+sm[i]-sm[q[h]]-L);
while(h<t&&!judge2(q[t-],q[t],i)) t--;
q[++t]=i;
}printf("%lld\n",f[N]); return ;
}

最新文章

  1. Android—IMEI
  2. h5+mui
  3. 【emWin】例程六:设置颜色
  4. R包之间冲突带来的奇怪错误
  5. while语句(1)
  6. 04 DOM一窥
  7. 轻量级应用开发之(04)UIScrollView-1
  8. 转: 深入理解 AngularJS 的 Scope
  9. 扩展BaseAdapter实现不存储列表项的ListView
  10. Mybatis异常There is no getter for property named &#39;XXX&#39; in &#39;class com.xxx.xxx.UserAccountDTO
  11. python发送post请求
  12. MATLAB求解二重积分案例
  13. TCP的TIME_WAIT
  14. reveal破解
  15. Spring4.0之四:Meta Annotation(元注解)
  16. linux进程端口防火墙
  17. List转换为字符串并添加分隔符
  18. sbt打包Scala写的Spark程序,打包正常,提交运行时提示找不到对应的类
  19. C++系统时间及字符串转换参考资料
  20. bzoj2286: [Sdoi2011]消耗战 虚树

热门文章

  1. .NET CORE下的Cache
  2. 基于BlogEngine.NET搭建个人博客
  3. MVC 使用cshtml的一些基础知识-和相关整理
  4. 把cnblogs变成简书 - cnblogs博客自定义皮肤css样式
  5. M1/M2 总结
  6. Linux学习期中总结
  7. 20135327郭皓--Linux内核分析第八周 进程的切换和系统的一般执行过程
  8. IT行业创新的读后感
  9. Beta 冲刺报告模板
  10. 微软开源的Trill是什么?