Submission #671799

# Submission time Handle Problem Language Result Execution time Memory
671799 2022-12-14T02:29:57 Z lam Lightning Conductor (POI11_pio) C++14
Compilation error
0 ms 0 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];
int p[maxn],q[maxn],k;
ld x[maxn];

ld f(int a, int b, int xx)
{
    return 1.0*sqrt(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)>=ép)
        {
            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)
{
    int l=1; int r=k; int z=-1;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (x[mid]>=idx)
        {
            z=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
//    cout<<idx<<" ::: "<<z<<'\n';
    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=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;
    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';
    }
}

Compilation message

pio.cpp: In function 'long long int bet(long long int, long long int, long long int)':
pio.cpp:25:46: error: '\U000000e9p' was not declared in this scope
   25 |         if (f(p[id],q[id],mid) - f(i,j,mid)>=ép)
      |                                              ^~