题目链接

BZOJ2216

题解

学过高中数学都应知道,我们要求\(p\)的极值,参变分离为

\[h_j + sqrt{|i - j|} - h_i \le p
\]

实际上就是求\(h_j + sqrt{|i - j|} - h_i\)的最大值

就可以设\(f[i]\)表示对\(i\)最大的该式的值

绝对值通常要去掉,一般可以通过方向性,我们只需每次转移时令\(i > j\),正反转移两次即可

现在式子变为

\[f[i] = max\{h_j + \sqrt{i - j}\} - h_i
\]

发现\(\sqrt{i - j}\)依旧无法处理,无法展开使用我们喜闻乐见的斜率优化

此时就可以考虑这个式子是否具有决策单调性

我们考虑对于\(i'<i\),我们的决策为\(h_j + sqrt{i' - j}\)

那么对于\(forall k < j\)有\(h_k + sqrt{i' - k} < h_j + sqrt{i' - j}\)

现在我们用\(i\)替换\(i'\)

式子变为\(h_k + sqrt{i - k}\)和\(h_j + sqrt{i - j}\)

\(h_k\)和\(h_j\)是没有变化的,如果\(sqrt{i - j}\)的增长比\(sqrt{i - k}\)的增长要快,我们就可认定\(i\)替换\(i'\)后,\(k\)依旧无法作为最优决策

考虑函数

\[f(x) = \sqrt{x}
\]

\[f'(x) = \frac{1}{2\sqrt{x}}
\]

显然当\(x\)越大增长率越慢,而\(i' - k > i' - j\),\(\sqrt{i - j}\)的增长的确比\(\sqrt{i - k}\)的增长要快

得证

所以用队列维护三元组优化即可

复杂度\(O(nlogn)\)

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 500005,maxm = 100005;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
double f[maxn],h[maxn];
int n,head,tail,ans[maxn];
struct tri{int l,r,pos;}q[maxn << 1];
inline double cal(int i,int j){
return h[j] + sqrt(i - j) - h[i];
}
inline bool check(int pos,int i,int j){
return cal(pos,i) >= cal(pos,j);
}
void work(){
q[head = tail = 0] = (tri){1,n,1};
tri u;
for (int i = 1; i <= n; i++){
ans[i] = max(ans[i],(int)ceil(cal(i,q[head].pos)));
q[head].l++;
if (q[head].l > q[head].r) head++;
while (head <= tail){
u = q[tail--];
if (!check(u.r,i,u.pos)){
q[++tail] = u;
if (u.r + 1 <= n) q[++tail] = (tri){u.r + 1,n,i};
break;
}
if (check(u.l,i,u.pos)){
if (head > tail){
q[++tail] = (tri){i + 1,n,i};
break;
}
continue;
}
else {
int l = u.l,r = u.r,mid;
while (l < r){
mid = l + r >> 1;
if (check(mid,i,u.pos)) r = mid;
else l = mid + 1;
}
q[++tail] = (tri){u.l,l - 1,u.pos};
q[++tail] = (tri){l,n,i};
break;
}
}
}
}
int main(){
n = read();
for (int i = 1; i <= n; i++) h[i] = read();
work();
reverse(h + 1,h + 1 + n);
reverse(ans + 1,ans + 1 + n);
work();
for (int i = n; i; i--)
printf("%d\n",ans[i]);
return 0;
}

BZOJ2216 [Poi2011]Lightning Conductor 【决策单调性dp】的更多相关文章

  1. LOJ2074/2157 JSOI2016/POI2011 Lightning Conductor 决策单调性DP

    传送门 我们相当于要求出\(f_i = \max\limits_{j=1}^{n} (a_j + \sqrt{|i-j|})\).这个绝对值太烦人了,考虑对于\(i>j\)和\(i<j\) ...

  2. 【BZOJ2216】[Poi2011]Lightning Conductor 决策单调性

    [BZOJ2216][Poi2011]Lightning Conductor Description 已知一个长度为n的序列a1,a2,...,an.对于每个1<=i<=n,找到最小的非负 ...

  3. P3515 [POI2011]Lightning Conductor[决策单调性优化]

    给定一序列,求对于每一个$a_i$的最小非负整数$p_i$,使得$\forall j \neq i $有$ p_i>=a_j-a_i+ \sqrt{|i-j|}$. 绝对值很烦 ,先分左右情况单 ...

  4. 洛谷 P3515 [ POI 2011 ] Lightning Conductor —— 决策单调性DP

    题目:https://www.luogu.org/problemnew/show/P3515 决策单调性... 参考TJ:https://www.cnblogs.com/CQzhangyu/p/725 ...

  5. BZOJ_2216_[Poi2011]Lightning Conductor_决策单调性

    BZOJ_2216_[Poi2011]Lightning Conductor_决策单调性 Description 已知一个长度为n的序列a1,a2,...,an. 对于每个1<=i<=n, ...

  6. BZOJ2216 Poi2011 Lightning Conductor 【决策单调性优化DP】

    Description 已知一个长度为n的序列a1,a2,...,an. 对于每个1<=i<=n,找到最小的非负整数p满足 对于任意的j, aj < = ai + p - sqrt( ...

  7. BZOJ2216: [Poi2011]Lightning Conductor(DP 决策单调性)

    题意 题目链接 Sol 很nice的决策单调性题目 首先把给出的式子移项,我们要求的$P_i = max(a_j + \sqrt{|i - j|}) - a_i$. 按套路把绝对值拆掉,$p_i = ...

  8. bzoj2216: [Poi2011]Lightning Conductor(分治决策单调性优化)

    每个pi要求 这个只需要正反DP(?)一次就行了,可以发现这个是有决策单调性的,用分治优化 #include<iostream> #include<cstring> #incl ...

  9. BZOJ2216 : [Poi2011]Lightning Conductor

    $f[i]=\max(a[j]+\lceil\sqrt{|i-j|}\rceil)$, 拆开绝对值,考虑j<i,则决策具有单调性,j>i同理, 所以可以用分治$O(n\log n)$解决. ...

随机推荐

  1. Linux TCP/IP调优参数 /proc/sys/net/目录

    所有的TCP/IP调优参数都位于/proc/sys/net/目录. 例如, 下面是最重要的一些调优参数,后面是它们的含义: /proc/sys/net/core/rmem_default " ...

  2. vbox虚拟机扩容(CentOS 7.2)

    Preface   My virtual machine was simply created by vagrant in default mode without anything about th ...

  3. Unity中StopCoroutine不起作用怎么办

    1,只有StartCoroutine使用一个字符串方法名时才能用StopCoroutine(string CoroutineName)停用. 2, public Coroutine coroutine ...

  4. python的30个编程技巧

     1.原地交换两个数字 x, y =10, 20 print(x, y) y, x = x, y print(x, y) 10 20 20 10 2.链状比较操作符 n = 10 print(1 &l ...

  5. Zabbix自动发现之fping

    原文发表于cu:2016-06-21 Zabbix自动发现功能从配置流程上比较简单:Discovery与Action. 在做Zabbix的自动发现验证时,使用"ICMP ping" ...

  6. Halcon如何保存仿射变换矩阵

    这里我们通过序列化来实现的,如下图,写到硬盘的HomMat2D_1内容和从硬盘里HomMat2D_2读出的内容一致,源代码在图片下方. Halcon源代码: hom_mat2d_identity (H ...

  7. ASP.NET MVC - 启动创建项目,未能加载错误

    VS2012以常规方式创建一ASP.NET MVC internet 项目.创建后F5启动项目,遇一错误: 未能加载文件或程序集“MySql.Web.v20, Version=6.9.4.0, Cul ...

  8. PHP中定义常量

    PHP中定义常量的方式如下: define(常量名,常量值); //定义常量PUBLISHER define('PUBLISHER', "O'Reilly & Associates& ...

  9. 冲刺ing-4

    第四次Scrum冲刺 队员完成的任务 队员 完成任务 吴伟华 Leangoo的看板截图,燃尽图 蔺皓雯 编写博客,学习后端设计 蔡晨旸 学习后端设计 曾茜 后端设计 鲁婧楠 服务器建构 杨池宇 学习后 ...

  10. PAT 甲级 1040 Longest Symmetric String

    https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 Given a string, you ar ...