# BZOJ2216 [POI2011] Lightning Conductor

https://www.luogu.com.cn/problem/P3515

 1 #include <bits/stdc++.h>
2 using namespace std;
3 #define LL long long
4
5 int n;
6 #define maxn 500011
8 struct quenode{int p,l,r;}que[maxn];
9 double f[maxn],g[maxn];
10 double cal(int j,int i) {return a[j]+sqrt(i-j)-a[i];}
11 void dp(double *f)
12 {
14     for (int i=1;i<=n;i++)
15     {
19         while (head<tail && cal(que[tail-1].p,que[tail-1].l)<cal(i,que[tail-1].l)) tail--;
21         else
22         {
23             int L=que[tail-1].l,R=que[tail-1].r+1;
24             while (L<R)
25             {
26                 int mid=(L+R)>>1;
27                 if (cal(que[tail-1].p,mid)>cal(i,mid)) L=mid+1;
28                 else R=mid;
29             }
30             if (L<=n)
31             {
32                 que[tail-1].r=L-1;
33                 que[tail++]=(quenode){i,L,n};
34             }
35         }
36     }
37 }
38
39 int main()
40 {
41     scanf("%d",&n);
42     for (int i=1;i<=n;i++) scanf("%d",&a[i]);
43     dp(f);
44     for (int i=1;i+i<=n;i++) {int t=a[i]; a[i]=a[n-i+1]; a[n-i+1]=t;}
45     dp(g);
46     for (int i=1;i<=n;i++) printf("%.0lf\n",max(0.,ceil(max(f[i],g[n-i+1]))));
47     return 0;
48 }
View Code

posted @ 2020-01-31 11:50  Blue233333  阅读(125)  评论(0编辑  收藏  举报