比赛 20191022轻松模拟测试 评测结果 AAAAAAAAAAA
题目名称 (USACO Dec18)平衡木 最终得分 100
用户昵称 rainy 运行时间 0.371 s
代码语言 C++ 内存使用 16.05 MiB
提交时间 2019-10-22 19:24:49
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long int_t;
char getch(){ static char buf[100000],*s1,*s2; return (s1 == s2) && (s2 = (s1 = buf) + fread(buf,1,100000,stdin)),s1 == s2 ? EOF : *s1++; }

#ifdef local
#define getch getchar
#endif

int_t read(){
    int_t x = 0, w = 1;char ch = 0;
    while(!isdigit(ch)) {ch = getch(); if(ch == '-') w = -1;}
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getch();
    return x * w;
}

const int_t maxn = 100010;

struct vec{
    double x,y;
    vec(double x=0, double y=0):x(x),y(y){}
    vec operator -(vec b){return vec(x - b.x,y - b.y);}
    double operator *(vec b){return x * b.y - y * b.x;}
};

int_t f[maxn],cnt;
vec stk[maxn];

void push(vec x){
    while(cnt && (x - stk[cnt]) * (stk[cnt] - stk[cnt-1]) <= 0) --cnt;
    stk[++cnt] = x;
}

int main(){
    freopen("balance_beam.in","r",stdin);
    freopen("balance_beam.out","w",stdout);
    int_t n = read();
    for(int_t i=1;i<=n;i++) f[i] = read(),push(vec(i,f[i]));
    push(vec(n+1,0));
    int_t now = 1;
    for(int_t i=1;i<=n;i++){
        while(stk[now].x < i) ++now;
        if(stk[now].x == i) cout<<int_t(stk[now].y * 100000)<<"\n";
        else cout<<int_t(((stk[now].x - i) * stk[now-1].y + stk[now].y * (i - stk[now-1].x)) / (stk[now].x - stk[now-1].x) * 100000)<< "\n";
    }
}