比赛 2024暑假C班集训9 评测结果 AAAAAAAAAAA
题目名称 (USACO Dec18)平衡木 最终得分 100
用户昵称 darkMoon 运行时间 0.166 s
代码语言 C++ 内存使用 6.39 MiB
提交时间 2024-07-09 10:32:52
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
auto mread = [](){
    int x;
    scanf("%lld", &x);
    return x;
};
const int N = 1e5 + 5;
const double eps = 1e-10;
int n, a[N], e[N], l[N], r[N];
deque<pair<int, int> > q;
int mato(int x_1, int y_1, int x_2, int y_2, int x_3, int y_3){
    return (y_3 - y_2) * (x_2 - x_1) >= (y_2 - y_1) * (x_3 - x_2);
}
signed main(){
    freopen("balance_beam.in", "r", stdin);
    freopen("balance_beam.out", "w", stdout);
    n = mread();
    for(int i = 1; i <= n; i ++){
        a[i] = mread();
    }
    q.push_back(mp(0, 0));
    e[0] = e[n + 1] = 1;
    for(int i = 1; i <= n; i ++){
        while(q.size() >= 2){
            int t = q.size() - 1;
            if(mato(q[t - 1].fi, q[t - 1].se, q[t].fi, q[t].se, i, a[i])){
                e[q[t].fi] = 0;
                q.pop_back();
            }
            else{
                break;
            }
        }
        e[i] = 1;
        q.push_back(mp(i, a[i]));
    }
    int la = 0;
    for(int i = 1; i <= n; i ++){
        if(e[i])
        la = i;
        l[i] = la;
    }
    q.push_back(mp(n + 1, 0));
    la = n + 1;
    for(int i = n; i >= 1; i --){
        if(e[i])
        la = i;
        r[i] = la;
    }
    for(int i = 1; i <= n; i ++){
        // printf("*** %lld %lld %lld\n", i, l[i], r[i]);
        if(e[i]){
            printf("%lld\n", a[i] * 100000);
        }
        else{
            printf("%lld\n", (int)((double)((double)a[l[i]] + (double)(a[r[i]] - a[l[i]]) / (double)(r[i] - l[i]) * (double)(i - l[i]) + eps) * 100000.0));
        }
    }
    return 0;
}