Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33607 LYLAKIOI 【S】T1 C++ 通过 100 442 MS 40100 KB 1694 2024-10-16 12:55:44

Tests(20/20):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define p_b push_back #define m_p make_pair typedef long long ll; typedef unsigned long long ull; using namespace std; const int maxn=2e6+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,a[maxn],stk[maxn],tp; int pre[maxn],nxt[maxn]; struct sgt { int T[maxn<<2]; #define ls(p) (p<<1) #define rs(p) (p<<1|1) void bd(int l,int r,int p){ if(l==r){ T[p]=a[l];return; }int mid=l+r>>1; bd(l,mid,ls(p)),bd(mid+1,r,rs(p)); T[p]=max(T[ls(p)],T[rs(p)]); }int qry(int l,int r,int s,int t,int p){ if(l<=s&&t<=r)return T[p]; int mid=s+t>>1,res=0; if(l<=mid)res=max(res,qry(l,r,s,mid,ls(p)));if(r>=mid+1)res=max(res,qry(l,r,mid+1,t,rs(p))); return res; } }T; void slv(){ n=read(); up(i,1,n)a[i]=read(); T.bd(1,n,1); up(i,1,n){ while(tp&&a[stk[tp]]>a[i])tp--; pre[i]=stk[tp]; stk[++tp]=i; }tp=0;stk[tp]=n+1; down(i,n,1){ while(tp&&a[stk[tp]]>=a[i])tp--; nxt[i]=stk[tp]; stk[++tp]=i; }ull res=0; up(i,1,n)res=max(res,(ull)a[i]*(ull)(nxt[i]-pre[i]-1)*(ull)T.qry(pre[i]+1,nxt[i]-1,1,n,1)); cout<<res; }int main(){ //freopen("a.in","r",stdin); //freopen("a.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }


测评信息: