4 级勾选手求助纸张问题!
查看原帖
4 级勾选手求助纸张问题!
766675
da_ke楼主2025/2/6 19:26
#include <bits/stdc++.h>

#define i64 long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define fdn(i,r,l) for(int i=(r);i>=(l);i--)
#define pii pair<int,int>
using namespace std;

typedef long long ll;
typedef double db;
typedef __int128 i128;

std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
std::mt19937_64 rnd64(std::chrono::steady_clock::now().time_since_epoch().count());

const int fyy=0;

ll pw(ll x){
    return x*x;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.in","r",stdin);
    freopen("out.out","w",stdout);
#endif
// 路虽远行则将至,事虽难做则必成。
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int N; ll L;
    cin>>N>>L; L++;
    vector<ll> S(N+1,0),dp(N+1,0);
    rep(i,1,N) cin>>S[i],S[i]+=S[i-1];
    rep(i,1,N) S[i]+=i;
    auto X=[&S,&L](int i)->ll{return S[i]+L;};
    auto Y=[&S,&dp,&L](int i)->ll{return dp[i]+(S[i]+L)*(S[i]+L);};
    vector<ll> q(N+1,0);
    int l=1,r=1;
    rep(i,1,N)
    {
        while(l<r&&Y(q[l+1])-Y(q[l])<=2*S[i]*(X(q[l+1])-X(q[l]))) l++;
        dp[i]=dp[l]+pw(S[i]-S[l]-L);
        while(l<r&&
        (Y(i)-Y(r))*(X(r)-X(r-1))
        <=(Y(r)-Y(r-1))*(X(i)-X(r))
        ) r--;
        q[++r]=i;
    }
    cout<<dp[N];
}

// 路虽远行则将至,事虽难做则必成。

又是用手机写的代码。莫名其妙的全 WA 了 qwq。因为只有手机,我瞪了半天无果

2025/2/6 19:26
加载中...