比赛 2024暑假C班集训9 评测结果 AAAAAAAAAAA
题目名称 (USACO Dec18)平衡木 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.116 s
代码语言 C++ 内存使用 5.56 MiB
提交时间 2024-07-09 09:41:02
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
const int N = 1e5+10;
const double eps = 1e-10;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}


int n;
ll f[N];
double ans[N];
int q[N],l,r,L,R;
int main(){
    freopen("balance_beam.in","r",stdin);
    freopen("balance_beam.out","w",stdout);
    n = read();
    for(int i = 1;i <= n;i++)f[i] = read();
    l = 1,r = 1;q[1] = 0;
    for(int i = 1;i <= n+1;i++){
        while(l < r && (f[i] - f[q[r]]) * (q[r] - q[r-1]) >= (f[q[r]] - f[q[r-1]]) * (i - q[r]))r--;
        q[++r] = i;
    }
    L = 1,R = 2;
    for(int i = 1;i <= n;i++){
        while(R <= r && q[R] < i)R++;
        while(L + 1 <= R && q[L+1] <= i)L++;
        if(i == q[L] || i == q[R])ans[i] = f[i];
        else{
            double k = (double)(f[q[R]] - f[q[L]]) / (q[R] - q[L]);
            ans[i] = (double)f[q[L]] + k * (double)(i - q[L]) + eps;
        }
    }
    for(int i = 1;i <= n;i++)printf("%lld\n",(long long)(ans[i] * 100000));
    
    return 0;
    
}