题意:https://www.luogu.com.cn/problem/P3195

思路:https://www.luogu.com.cn/problemnew/solution/P3195

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr strcat
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
#include <iomanip>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
clock_t __START,__END;
double __TOTALTIME;
void _MS(){__START=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const double E=2.718281828;
const double PI=acos(-1.0);
const ll INF=(1LL<<);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int n,L;
int a[N];
db dp[N],sum[N];
db A(int x)
{
return sum[x]+x;
}
db B(int x)
{
return sum[x]+x+L+;
}
db X(int x)
{
return B(x);
}
db Y(int x)
{
return dp[x]+B(x)*B(x);
}
double slope(int a,int b)
{
return 1.0*(Y(a)-Y(b))/(1.0*(X(a)-X(b)));
} class mydeque{
public:
int len=;
int p[N];
int l,r,tot;
void init()
{
l=;r=;
tot=;
}
int size()
{
return tot;
}
int pos(int x)
{
return (x+len)%len;
}
int f()
{
return p[l];
}
int b()
{
return p[r];
}
void pf(int x)
{
tot++;
l=pos(l-);
p[l]=x;
}
void pb(int x)
{
tot++;
r=pos(r+);
p[r]=x;
}
void popf()
{
p[l]=;
l=pos(l+);
tot--;
}
void popb()
{
p[r]=;
r=pos(r-);
tot--;
}
}q; int main()
{
q.init();//初始化有dp[0](l=r=1而不是l=1,r=0,tot=0),因为要用到
sc("%d%d",&n,&L);
for(int i=;i<=n;++i)sc("%d",&a[i]),sum[i]=a[i]+sum[i-];
for(int i=;i<=n;++i)
{
while(q.l<q.r&&slope(q.f(),q.p[q.pos(q.l+)])<2.0*A(i))q.popf();
dp[i]=dp[q.f()]+(A(i)-B(q.f()))*(A(i)-B(q.f()));
while(q.l<q.r&&slope(q.p[q.pos(q.r-)],q.b())>slope(q.p[q.pos(q.r-)],i))q.popb();
q.pb(i);
}
pr("%lld\n",(ll)dp[n]);
return ;
} /**************************************************************************************/

最新文章

  1. 初学My Batis之入门
  2. jQuery 安装方法
  3. C# 执行JS
  4. bat完美关机命令
  5. thinkphp 模板显示display和assign的用法
  6. 各种语言简单的输出Hello World
  7. NOI2002银河英雄传说
  8. [分享]WPF 虚拟键盘
  9. //string scriptstrs = &quot;&lt;script&gt;alert(&#39;欢迎光临!&#39;);&lt;/script&gt;&quot;;
  10. AspectJ的安装和Eclipse的AJDT插件的配置
  11. mysqldump报错
  12. VS2010发布、打包安装程序(超全超详细)
  13. 设计模式-行为型模式,python 中介者模式
  14. 隐藏响应的server,X-Powered-By
  15. Humble Numbers HDU - 1058
  16. 黄聪:Windows+PHP7+ImageMagick
  17. javascript prototype学习
  18. C#集合之栈
  19. 图的第k短路
  20. 在Eclipse中连接SQL

热门文章

  1. Echarts案例-折线图
  2. NOI2019 游记——一切都是最好的安排
  3. css定位中的百分比
  4. Jmeter Web 性能测试入门 (四):一个小实例带你学会 Jmeter 脚本编写
  5. (一)OpenCV-Python学习—基础知识
  6. 免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器
  7. CentOS源码安装 Tomcat/8.0.24
  8. Python 调用outlook发送邮件(转 )
  9. Java动态修改运行环境
  10. as 什么意思?