题目链接

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. Scrapy爬取美女图片续集 (原创)

    上一篇咱们讲解了Scrapy的工作机制和如何使用Scrapy爬取美女图片,而今天接着讲解Scrapy爬取美女图片,不过采取了不同的方式和代码实现,对Scrapy的功能进行更深入的运用.(我的新书< ...

  2. 查看Linux系统版本的命令

    1.lsb_release -a,即可列出所有版本信息: [root@S-CentOS ~]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0 ...

  3. symfony注册Twig模板中使用自定义PHP方法

    // 注:只是在此做下记录,有兴趣的可以参考,不做实际教程文档// 官方文档,https://symfony.com/doc/2.8/templating/twig_extension.html// ...

  4. 用php做个简单的日历

    存档: index.php <html> <head> <title>日历</title> <style> table{border:1px ...

  5. C++自学第二课:对象和类的概念

    既然是C++,比C语言多了最重要的概念:面向对象. 面向对象?对象是什么?Girlfriend? 我天天面向她也没学会C++. 我觉得对象就是有统一特征的一类编程目标. 打个比方说墙上有个开关,我一按 ...

  6. Java基础知识:Java实现Map集合二级联动4

    comboBox.setModel(new DefaultComboBoxModel(getProvince())); // 添加省份信息 final JLabel label = new JLabe ...

  7. Arctic Network POJ 2349 (最小生成树思想)

    Description The Department of National Defence (DND) wishes to connect several northern outposts by ...

  8. Wormholes POJ 3259(SPFA判负环)

    Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...

  9. HDU 5434 Peace small elephant 状压dp+矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant  Accepts: 38  Submissions: ...

  10. Hexo博客搭建全解

    [原创,转载请附网址:http://dongshuyan.top] 欢迎来到莫与的博客,第一篇记录了一下怎么写一篇博客,以方便之后写博客~ #从配置说起下载安装Git与Node.js略过 1.安装he ...