Submission #7927292


Source Code Expand

#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int stk[200010],tp,a[200010],L[200010],R[200010],n;
void work(int*A){
	tp=0;
	for(int i=1;i<=n;++i){
		while(tp&&a[stk[tp]]>a[i])--tp;
		A[i]=i-stk[tp];
		stk[++tp]=i;
	}
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=gi();
	for(int i=1;i<=n;++i)a[i]=gi();
	work(L);std::reverse(a+1,a+n+1);work(R);
	ll ans=0;
	for(int i=1;i<=n;++i)
		ans+=1ll*a[i]*L[n-i+1]*R[i];
	printf("%lld\n",ans);
	return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User test12345
Language C++14 (GCC 5.4.1)
Score 400
Code Size 649 Byte
Status AC
Exec Time 17 ms
Memory 3328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 14 ms 3328 KB
corner1 AC 14 ms 3328 KB
corner2 AC 1 ms 256 KB
corner3 AC 16 ms 2944 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 17 ms 2560 KB
maxrand1 AC 17 ms 2560 KB
maxrand2 AC 17 ms 2560 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB