Submission #671807

# Submission time Handle Problem Language Result Execution time Memory
671807 2022-12-14T02:49:24 Z lam Lightning Conductor (POI11_pio) C++14
72 / 100
127 ms 32660 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long double ld;
const int maxn = 1e6 + 10;
const ld eps = 1e-9;
int n,h[maxn]; ld ans[maxn],ans2[maxn],sq[maxn];
int p[maxn],q[maxn],k;
ld x[maxn];
int cnt=1;

ld f(int a, int b, int xx)
{
    return 1.0*sq[xx-a] + b;
}

int bet(int id, int i, int j)
{
    if (q[id]>=j) return n;
    if (f(p[id],q[id],i)<j) return i-1;
    int l=i; int r=n;
    int ans=n;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (f(p[id],q[id],mid) - f(i,j,mid)>=eps)
        {
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return ans;
}

void add(int i, int j)
{
    if (k==0)
    {
        k++;
        p[k]=i; q[k]=j;
        x[k]=n;
        return;
    }
    x[k]=bet(k,i,j);
    while (k>1&&x[k-1]>=x[k])
    {
        k--;
        x[k]=bet(k,i,j);
    }
    k++;
    p[k]=i; q[k]=j;
    x[k]=n;
}


/**
f(x) = sqrt(x-a) + b
bet(

**/

ld qry(int idx)
{
    while (cnt<k&&x[cnt]<idx) cnt++;
    int z=cnt;
    return f(p[z],q[z],idx);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin>>n;
    for (int i=0; i<=n; i++) sq[i]= 1.0*sqrt(i);
    for (int i=1; i<=n; i++) cin>>h[i];
    k=0;
    for (int i=1; i<=n; i++)
    {
        add(i-1,h[i]);
//        for (int j=1; j<=k; j++) cout<<p[j]<<','<<q[j]<<". "<<x[j]<<" : "; cout<<'\n';
        ans[i]=qry(i-1);
    }
    reverse(h+1,h+n+1); k=0; cnt=0;
    for (int i=1; i<=n; i++)
    {
        add(i-1,h[i]);
//        for (int j=1; j<=k; j++) cout<<p[j]<<','<<q[j]<<". "<<x[j]<<" : "; cout<<'\n';
        ans2[n-i+1]=qry(i-1);
    }
    reverse(h+1,h+n+1);
    for (int i=1; i<=n; i++)
    {
        int res = ceil(max(ans[i],ans2[i]))-h[i];
//        cout<<ans[i]<<' '<<ans2[i]<<'\n';
        cout<<res<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4224 KB Output is correct
2 Correct 13 ms 4180 KB Output is correct
3 Correct 16 ms 4448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6120 KB Output is correct
2 Incorrect 28 ms 6072 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13980 KB Output is correct
2 Correct 60 ms 13796 KB Output is correct
3 Correct 52 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 23072 KB Output is correct
2 Correct 92 ms 20940 KB Output is correct
3 Correct 76 ms 23124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 32660 KB Output is correct
2 Incorrect 127 ms 29840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 30284 KB Output is correct
2 Incorrect 123 ms 29648 KB Output isn't correct
3 Halted 0 ms 0 KB -