Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
38258 hi_hi 【J】T2 C++ 运行超时 70 1000 MS 76860 KB 1247 2025-09-25 13:23:12

Tests(7/10):


#include<bits/stdc++.h> using namespace std; int n,a[2000006],ci,ji[2000006],nxt[2000006],pre[2000006]; struct sss{ int l,r,as; bool operator<(const sss x)const{ return x.as<as; } }; priority_queue<sss>q; int main(){ //freopen("legion.in","r",stdin); //freopen("legion.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(i!=1){ pre[i]=i-1; } if(i!=n){ nxt[i]=i+1; } } for(int i=1;i<n;i++){ q.push((sss){i,i+1,max(a[i],a[i+1])}); } long long ans=0,top=n; while(ci<n-1){ sss now=q.top(); if(ji[now.l]!=0 || ji[now.r]!=0 || now.l==0 || now.r==0){ q.pop(); continue; } ans+=now.as; ji[now.l]=1; ji[now.r]=1; top++; a[top]=now.as; nxt[top]=nxt[now.r]; pre[top]=pre[now.l]; nxt[pre[now.l]]=top; pre[nxt[now.r]]=top; ci++; q.pop(); if(nxt[top]!=0)q.push((sss){top,nxt[top],max(a[top],a[nxt[top]])}); if(pre[top]!=0)q.push((sss){pre[top],top,max(a[top],a[pre[top]])}); } printf("%lld",ans); }


测评信息: