QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789213#9440. Train Seatsgrass8cowWA 6ms26476kbC++172.1kb2024-11-27 19:34:142024-11-27 19:34:14

Judging History

This is the latest submission verdict.

  • [2024-11-27 19:34:14]
  • Judged
  • Verdict: WA
  • Time: 6ms
  • Memory: 26476kb
  • [2024-11-27 19:34:14]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n;
#define ll long long
#define pi pair<ll,ll>
#define fi first
#define se second
#define pb push_back
ll a[201000];
vector<int>g1[201000],g2[201000];
pi el[201000],er[201000];
int top,sta[201000];
pi operator + (const pi &a,const pi &b){return {a.fi+b.fi,a.se+b.se};}
pi xf(pi a){return {-a.fi,-a.se};}
ll nl[201000],nr[201000];
int xx[401000],rk[401000];
bool v1[201000];
ll su[1601000];
pi as[1601000];
void up(int p,int l,int r,int x,pi z){
    if(l==r){as[p]=z;return;}
    int mid=(l+r)>>1;
    if(x<=mid)up(p<<1,l,mid,x,z);else up(p<<1|1,mid+1,r,x,z);
    as[p]=as[p<<1]+as[p<<1|1];
    su[p]=su[p<<1]+su[p<<1|1]+as[p<<1].fi*as[p<<1|1].se;
}
ll ans[201000];
ll b[200100],M;
bool cop(pi a,pi b){return a.fi*b.se<b.fi*a.se;}
int main(){
    scanf("%d%lld",&n,&M);b[n+1]=M+1;
    for(int i=1;i<=n;i++)scanf("%lld",&b[i]);n++;
    ll all=0;
    for(int i=1;i<=n;i++)a[i]=b[i]-b[i-1],a[i]=-a[i],all+=a[i];
    for(int i=1;i<=n;i++){
        nl[i]=nl[i-1];
        pi e={a[i],1};
        while(top&&cop(el[sta[top]],e))v1[sta[top]]=1,
        g1[i].pb(sta[top]),nl[i]+=e.fi*el[sta[top]].se,e=e+el[sta[top]],top--;
        el[i]=e,sta[++top]=i;
    }
    top=0;
    for(int i=n;i;i--){
        nr[i]=nr[i+1];
        pi e={a[i],1};
        while(top&&cop(er[sta[top]],e))
        g2[i].pb(sta[top]),nr[i]+=e.fi*er[sta[top]].se,e=e+er[sta[top]],top--;
        er[i]=e,sta[++top]=i;
    }
    for(int i=1;i<=n*2;i++)xx[i]=i;
    sort(xx+1,xx+n*2+1,[&](int a,int b){return cop((a<=n)?el[a]:er[a-n],(b<=n)?el[b]:er[b-n]);});
    for(int i=1;i<=n*2;i++)rk[xx[i]]=i;
    for(int i=1;i<=n;i++)if(!v1[i])up(1,1,n*2,rk[i],el[i]);
    for(int i=n;i;i--){
        for(int o:g1[i])up(1,1,n*2,rk[o],el[o]);
        up(1,1,n*2,rk[i],{0,0});
        if(i<n){
            for(int o:g2[i+1])up(1,1,n*2,rk[o+n],{0,0});
            up(1,1,n*2,rk[i+1+n],er[i+1]);
        }
        ans[i]=nl[i-1]+nr[i+1]+a[i]*(n-1)+su[1]+(all-a[i]);
    }
    ll mx=0;
    for(int i=1;i<=n;i++)mx=max(mx,-ans[i]);printf("%lld",mx);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 26476kb

input:

3 10
3 7 10

output:

28

result:

ok "28"

Test #2:

score: 0
Accepted
time: 3ms
memory: 22604kb

input:

5 20
3 10 11 14 17

output:

73

result:

ok "73"

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 24440kb

input:

10 1000000000
136909656 243332691 643531997 505919307 43553384 657638276 57213246 179732866 357373203 182482400

output:

7174795384

result:

wrong answer 1st words differ - expected: '7649951260', found: '7174795384'