社区讨论
70分(wa三个),求助
P2422良好的感觉参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @m2l8zm5n
- 此快照首次捕获于
- 2024/10/23 10:21 去年
- 此快照最后确认于
- 2025/11/04 16:28 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
inline int read(){
register int x=0,ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch<='9'&&ch>='0'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x;
}
#define int long long
int a[100005],st[100005],f[100005],q[100005];
signed main()
{
//freopen("P2422_9.in","r",stdin);
register int i,j,n,s,t,x,y,ans=0;
cin>>n;
for(i=1;i<=n;i++) st[i]=st[i-1]+(a[i]=read());
s=1; t=0;
for(i=1;i<=n;i++){
while(s<=t&&a[q[t]]>=a[i]) t--;
q[++t]=i;
x=a[q[s]]*(st[i]-st[q[s-1]]);
while(s<t&&x<=a[q[s+1]]*(st[i]-st[q[s]])){
x=a[q[s+1]]*(st[i]-st[q[s]]); s++;
}
f[i]=x;
//printf("f[%lld]=%lld q[s]=%lld q[t]%lld\n",i,f[i],q[s],q[t]);
ans=max(ans,f[i]);
}
cout<<ans;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...