首页 > 其他 > 详细

[POI2011]Lightning Conductor

时间:2020-01-30 18:02:40      阅读:86      评论:0      收藏:0      [点我收藏+]

题目描述

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.

题意翻译

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

1 \le n \le 5\times 10^{5}1n5×105,0 \le a_i \le 10^{9}0ai?109 。

输入输出样例

输入 #1
6
5
3
2
4
2
4
输出 #1
2
3
5
3
5
4
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 typedef long long ll;
 6 int q[500005],R[500005],a[500005],n,b[500005];
 7 double sq[500005],f1[500005],f2[500005];
 8 double getValue(int x,int y)
 9 {
10     return a[y]+(sq[x-y]);
11 }
12 int binary(int x,int y)
13 {
14     int l=x,r=n+1;
15     while (l<r)
16     {
17         int mid=(l+r)/2;
18         if (getValue(mid,y)<=getValue(mid,x)) r=mid;
19         else l=mid+1;
20     }
21     return l;
22 }
23 int main()
24 {int i,j;
25     scanf("%d",&n);
26     for (i=1;i<=n;i++)
27     {
28         scanf("%d",&a[i]);
29         sq[i]=sqrt((double)i);
30     }
31     int h=1,t=0;
32     for (i=1;i<=n;i++)
33     {
34         while (h<t&&R[t-1]>=binary(i,q[t])) t--;
35         R[t]=binary(i,q[t]);
36         q[++t]=i;
37         while (h<t&&R[h]<=i) h++;
38         f1[i]=getValue(i,q[h]);
39     }
40     h=1,t=0;
41     for (i=1;i<=n;i++)
42     b[i]=a[n-i+1];
43     for (i=1;i<=n;i++)
44     a[i]=b[i];
45     for (i=1;i<=n;i++)
46     {    
47         while (h<t&&R[t-1]>=binary(i,q[t])) t--;
48         R[t]=binary(i,q[t]);
49         q[++t]=i;
50         while (h<t&&R[h]<=i) h++;
51         f2[n-i+1]=getValue(i,q[h]);
52     }
53     for (i=1;i<=n;i++)
54     printf("%.0lf %.0lf\n",f1[i],f2[i]);
55     for (i=1;i<=n;i++)
56     printf("%d\n",(int)ceil(max(f1[i],f2[i]))-a[n-i+1]);
57 }
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 int a[500005],n,b[500005];
 8 double sq[500005],f1[500005],f2[500005];
 9 void solve1(int l,int r,int L,int R)
10 {int i,Mid=0;
11     if (l>r) return;
12     int mid=(l+r)/2;
13     double s=0;
14     f1[mid]=a[mid];Mid=mid;
15     for (i=L;i<=min(R,mid);i++)
16     {
17         s=a[i]+sq[mid-i];
18         if (s>f1[mid]) f1[mid]=s,Mid=i; 
19     }
20     solve1(l,mid-1,L,Mid);
21     solve1(mid+1,r,Mid,R);
22 }
23 void solve2(int l,int r,int L,int R)
24 {int i,Mid=0;
25     if (l>r) return;
26     int mid=(l+r)/2;
27     double s=0;
28     f2[n-mid+1]=a[mid];Mid=mid;
29     for (i=L;i<=min(R,mid);i++)
30     {
31         s=a[i]+sq[mid-i];
32         if (s>f2[n-mid+1]) f2[n-mid+1]=s,Mid=i; 
33     }
34     solve2(l,mid-1,L,Mid);
35     solve2(mid+1,r,Mid,R);
36 }
37 int main()
38 {int i,j;
39     scanf("%d",&n); 
40     for (i=1;i<=n;i++)
41     {
42         scanf("%d",&a[i]);
43         sq[i]=sqrt((double)i);
44     } 
45     solve1(1,n,1,n);
46     for (i=1;i<=n;i++)
47     b[i]=a[n-i+1];
48     for (i=1;i<=n;i++)
49     a[i]=b[i];
50     solve2(1,n,1,n);
51     for (i=1;i<=n;i++)
52     printf("%d\n",(int)ceil(max(f1[i],f2[i]))-a[n-i+1]);
53 }

 

[POI2011]Lightning Conductor

原文:https://www.cnblogs.com/Y-E-T-I/p/12243143.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!