Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33621 22fhq 【S】T1 C++ 通过 100 900 MS 195572 KB 1373 2024-10-16 15:15:47

Tests(20/20):


#include<bits/stdc++.h> using namespace std; int n,h[2000006],nl,nr; int mx[2000006][21],lg[2000006]; int pre[2000006],nxt[2000006]; void init(){ for(int i=1;i<=n;i++)mx[i][0]=h[i]; lg[1]=0; for(int i=2;i<=n;i++)lg[i]=lg[i>>1]+1; for(int j=1;j<=20;j++){ for(int i=1;i<=n;i++){ if(i+(1<<j)-1>n)break; mx[i][j]=max(mx[i][j-1],mx[i+(1<<j-1)][j-1]); } } } int qumx(int l,int r){ return max(mx[l][lg[r-l+1]],mx[r-(1<<lg[r-l+1])+1][lg[r-l+1]]); } signed main(){ //auto i1=freopen("a.in","r",stdin); //i1=freopen("a.out","w",stdout); cin>>n; for(int i=1;i<=n;i++)cin>>h[i]; init(); stack<int>st; for(int i=1;i<=n;i++){ while(st.size()&&h[st.top()]>=h[i])st.pop(); if(st.empty())pre[i]=0; else pre[i]=st.top(); st.push(i); } while(st.size())st.pop(); for(int i=n;i>=1;i--){ while(st.size()&&h[st.top()]>=h[i])st.pop(); if(st.empty())nxt[i]=n+1; else nxt[i]=st.top(); st.push(i); } unsigned long long ans=0; for(int i=1;i<=n;i++){ int l=pre[i]+1,r=nxt[i]-1; unsigned long long a=qumx(l,r); a*=h[i]; a*=(r-l+1); ans=max(ans,a); } cout<<ans; // cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; return 0; }


测评信息: