首页 > 其他分享 >【题解】P3515 [POI2011]Lightning Conductor(二分栈/分治优化DP)

【题解】P3515 [POI2011]Lightning Conductor(二分栈/分治优化DP)

时间:2022-12-30 20:44:18浏览次数:64  
标签:building le conductor Conductor int 题解 POI2011 height lightning

[POI2011]Lightning Conductor

题面翻译

给定一个长度为 \(n\) 的序列 \(\{a_n\}\),对于每个 \(i\in [1,n]\) ,求出一个最小的非负整数 \(p\) ,使得 \(\forall j\in[1,n]\),都有 \(a_j\le a_i+p-\sqrt{|i-j|}\)

\(1 \le n \le 5\times 10^{5}\),\(0 \le a_i \le 10^{9}\) 。

题目描述

Progressive climate change has forced the Byteburg authorities to build a huge lightning conductor that would protect all the buildings within the city.

These buildings form a row along a single street, and are numbered from to .

The heights of the buildings and the lightning conductor are non-negative integers.

Byteburg's limited funds allow construction of only a single lightning conductor.

Moreover, as you would expect, the higher it will be, the more expensive.

The lightning conductor of height located on the roof of the building (of height ) protects the building (of height ) if the following inequality holds:

where denotes the absolute value of the difference between and .

Byteasar, the mayor of Byteburg, asks your help.

Write a program that, for every building , determines the minimum height of a lightning conductor that would protect all the buildings if it were put on top of the building .

输入格式

In the first line of the standard input there is a single integer () that denotes the number of buildings in Byteburg.

Each of the following lines holds a single integer () that denotes the height of the -th building.

输出格式

Your program should print out exactly lines to the standard output.

The -th line should give a non-negative integer denoting the minimum height of the lightning conductor on the -th building.

样例 #1

样例输入 #1

6
5
3
2
4
2
4

样例输出 #1

2
3
5
3
5
4

题解

先只考虑转移点小于当前点的情况。
画出转移点关于i的函数,可以发现两函数之间最多只有一个交点。
于此,可以得出二分栈做法或者决策单调性(四边形不等式也可以证)。
有决策单调性不要死证,可以画图辅助证明/打表/感性理解都是好的做法。

#include<bits/stdc++.h>
using namespace std;
inline int rd(){
	int f=1,j=0;
	char w=getchar();
	while(!isdigit(w)){
		if(w=='-')f=-1;
		w=getchar();
	}
	while(isdigit(w)){
		j=j*10+w-'0';
		w=getchar();
	}
	return f*j;
}
const int N=500010;
int n,sum[N];
double sq[N],f[N];
void deal(int l,int r,int L,int R){
	if(l>r)return ;
	int mid=(l+r)/2,p;
	double maxn=0;
	for(int i=L;i<=min(mid,R);i++){
		if(sq[mid-i]+sum[i]>maxn)maxn=sq[mid-i]+sum[i],p=i;
	}
//	cout<<mid<<":"<<p<<" "<<maxn<<"\n";
	f[mid]=max(f[mid],maxn);
	deal(l,mid-1,L,p),deal(mid+1,r,p,R);
	return ;
}
signed main(){
	n=rd();
	for(int i=1;i<=n;i++)sum[i]=rd(),sq[i]=sqrt(i),f[i]=0;
	deal(1,n,1,n);
	for(int i=1;i<=n/2;i++)swap(sum[i],sum[n-i+1]),swap(f[i],f[n-i+1]);
	deal(1,n,1,n);
	for(int i=n;i>=1;i--)printf("%d\n",(int)(ceil(f[i])-sum[i]));
	return 0;
}

双倍经验

标签:building,le,conductor,Conductor,int,题解,POI2011,height,lightning
From: https://www.cnblogs.com/T-water/p/17015783.html

相关文章

  • 本博客提供的题解仅供学习,请勿抄袭代码
    近日,发现有部分同学翻取博客上的题解程序复制提交的抄袭行为;在此声明:本博客的代码仅供大家学习参考,对于自身还未学习到对应知识点的同学,请先完善自身基础知识的学习,当且仅......
  • 洛谷P2296 [NOIP2014 提高组] 寻找道路 题解
    题目链接:P2296[NOIP2014提高组]寻找道路-洛谷|计算机科学教育新生态(luogu.com.cn)好了,话不多说上代码:1#include<bits/stdc++.h>2usingnamespacestd;3......
  • Ynoi2019模拟赛题解
    \(Ynoi2019\)模拟赛题解前言:第一次做\(Ynoi\)还是有被离谱到的,我从来没有做到过这么卡常的题目,我到现在\(T1\)都还是\(70\)分,\(lxl\)毒瘤名不虚传啊。但是不得不说,\(Ynoi......
  • 【题解】P1973 [NOI2011] NOI 嘉年华
    yyc学长说是典题,就记一下。题意给出\(n\)个区间,试在丢弃一些区间后,把区间分成两部分,使得不存在同时被两部分中的区间覆盖的位置,求:最终包含区间数较小的部分的区间......
  • 【题解】P1527 [国家集训队]矩阵乘法(整体二分)
    [国家集训队]矩阵乘法题目描述给你一个\(n\timesn\)的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第\(k\)小数。输入格式第一行有两个整数,分别表示矩阵大小\(n......
  • 恶意竞争题解
    恶意竞争题目大意:巨软和微硬两家公司是竞争对手,微硬希望从巨软公司的软件中找到漏洞来打击竞品的销量。巨软公司的软件有\(s\)个子组件,漏洞分为\(n\)类,微硬公司希望在其......
  • Error: Failed to upgrade Homebrew Portable Ruby! 问题解决
    brewconfig==>Downloadinghttps://mirrors.ustc.edu.cn/homebrew-bottles/bottles/bottles-portable-ruby/portable-ruby-2.6.8_1.el_capitan.bottle.tar.gzcurl:(22......
  • 【Qt】问题解决:Unable to create a debugging engine.
    ......
  • AcWing 4818.奶牛大学 题解
    形式化题意给定一个整数\(N\)和一个序列\(c\)(\(|c|=N\)),试找出一个最小的\(x\),使得\(f(x)=(\sum\limits_{i=1}^{N}c_i>=x)\timesx\)的值最大大概思路由于\(......
  • INTENT2022--一道包含12个反调试反虚拟机操作的ctf题解
    作者:selph查看全文请去公众号:极安御信安全研究院查看原文。从一道Re题学习12种反调试反虚拟技术题目:AntiDebuggingEmporium来源:INTENTCTF2022Re这个题目很有意思,里......