被卡精度了求调
查看原帖
被卡精度了求调
1013955
1234567890sjx楼主2024/10/2 19:41

111

// #pragma GCC optimize(3)
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define int long long
#define F(i,x,y) for(int i=x;i<=y;++i)
#define G(i,x,y) for(int i=x;i>=y;--i)
#define FD(i,x,y) for(int i=x;i*i<=y;++i)
#define GD(i,x,y) for(int i=x;i*i>=y;--i)
#define adde(x,y) z[x].eb(y);
#define Adde(x,y) z[x].eb(y),z[y].eb(x);
#define addew(x,y,w) z[x].eb(y,w)
#define Addew(x,y,w) z[x].eb(y,w),z[y].eb(x,w)
#define FIMX(X) memset(X,0x3f,sizeof X)
#define FIMI(X) memset(X,-0x3f,sizeof X)
#define FI0(X) memset(X,0,sizeof X)
#define FIN(X) memset(X,-1,sizeof X)
#define rng(X) X.begin(),X.evis()
#define PII pair<int,int>
#define PDD pair<doublocke,doublocke>
#define PIII tuple<int,int,int>
#define VI vector<int>
#define VII vector<PII>
#define VID vector<pair<int,doublocke>>
#define VDD vector<PDD>
using namespace std;
char *p1,*p2,buf[1000100];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000096,stdin),p1==p2)?EOF:*p1++)
inline int read(){
    int x=0;char c=gc();
    while(c<48)c=gc();
    while(c>47)x=(x<<3)+(x<<1)+(c&15),c=gc();
    return x;
}
char pool[1000100];
int idxtop=0;
void flush(){
    int i;
    for(i=0;i+8<idxtop;i+=8){
        putchar(pool[i]);
        putchar(pool[i+1]);
        putchar(pool[i+2]);
        putchar(pool[i+3]);
        putchar(pool[i+4]);
        putchar(pool[i+5]);
        putchar(pool[i+6]);
        putchar(pool[i+7]);
    }
    for(;i<idxtop;++i)putchar(pool[i]);
    idxtop=0;
}
void print(int x){
    int xv[20],nt=0;
    do{
        xv[++nt]=(x%10)^48;
        x/=10;
    }while(x);
    for(int i=nt;i;--i)pool[idxtop++]=xv[i];
    if(idxtop>998244)flush();
}
void print(char o){
    pool[idxtop++]=o;
    if(idxtop>998244)flush();
}
__int128 lcm(__int128 x,__int128 y){
    return x/__gcd(x,y)*y;
}
const int pw=100000;
const int N=100100;
int a[N],stk[N],stktop;
int cha(int x,int xx,int y,int yy){
    return x*yy-xx*y;
}
int op(int x,int y,int z){
    return cha(x-y,a[x]-a[y],x-z,a[x]-a[z])<=0;
}
void solve(unsigned __testid = 1) {
    int n=read();
    F(i,1,n)a[i]=read(),a[i]*=pw;
    a[0]=a[n+1]=0;
    stk[++stktop]=0;
    F(i,1,n){
        while(stktop>1&&op(i,stk[stktop],stk[stktop-1]))--stktop;
        stk[++stktop]=i;
    }
    stk[++stktop]=n+1;
    F(i,1,n){
        int l=1,r=stktop,best=-1;
        while(l<=r){
            int mid=l+r>>1;
            if(stk[mid]<=i)best=mid,l=mid+1;
            else r=mid-1;
        }
        // cout<<i<<": "<<a[stk[best]]<<' '<<a[stk[best+1]]<<'\n';
        if(a[stk[best+1]]>=a[stk[best]])printf("%lld\n",a[stk[best]]+(i-stk[best])*(a[stk[best+1]]-a[stk[best]])/(stk[best+1]-stk[best]));
        else printf("%lld\n",a[stk[best]]-((i-stk[best])*(a[stk[best]]-a[stk[best+1]])+stk[best+1]-stk[best]-1)/(stk[best+1]-stk[best]));
    }
}
void Presolve() {
}
int32_t main(){
    // freopen("graph.in","r",stdin);
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
    int T;
    T=1;
    // cin>>T;
    Presolve();
    F(_,1,T)
        solve((unsigned)_);
    flush();
    return 0;
}

/*
6
3 6 1 4 5 2

300000
600000
566666
533333
500000
200000
*/

2024/10/2 19:41
加载中...