QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120096 | #5500. Bars | xuzz | WA | 1ms | 5660kb | C++14 | 974b | 2023-07-06 13:29:48 | 2023-07-06 13:29:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') f=(ch=='-')?-1:1,ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
const int N=2000005;
int a[N],fa[N];
long long ans;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
// freopen("wifi.in","r",stdin);
// freopen("wifi.out","w",stdout);
int n=read();a[1]=read(),fa[1]=1,ans=1ll*a[1]*(n-1);
for(int i=2;i<=n;i++)
{
a[i]=read();int f=find(i-1);
long long s=1ll*(n-f)*a[i]-1ll*(n-i)*a[f];
// cout<<s<<' '<<f<<endl;
if(s>0)
{
ans+=s;int ff=find(f-1);
// cout<<ans<<endl;
while(ff)
{
s=1ll*(f-ff)*(a[i]-a[f])+1ll*(i-f)*(a[ff]-a[f]);
if(s<=0) break;
// cout<<i<<' '<<f<<' '<<ff<<' '<<s<<' ';
ans+=s,fa[f]=ff,f=ff,ff=find(f-1);
// cout<<ans<<endl;
}
fa[i]=i;
}
else fa[i]=i-1;
}
printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5660kb
input:
2 4 5 2 2 6 5 1 5 4 4 1
output:
9
result:
wrong answer 1st lines differ - expected: '33', found: '9'