南昌网络赛Max Answer

Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval.
Now she is planning to find the max value of the intervals in her array. Can you help her?

Input
First line contains an integer n(1 \le n \le 5 \times 10 ^5n(1≤n≤5×10 ^5).
Second line contains nn integers represent the array a(−10^5 ≤a i≤10^5 ).
Output
One line contains an integer represent the answer of the array.
样例输入 复制
5
1 2 3 4 5
样例输出 复制
36

#include
#include
#include
#include
using namespace std;
const int N=5*1e5+10;
long long dpmin[N][21],dpsumx[N][21],dpsumd[N][21],a[N],sum[N];int n;
void ST1()
{
	for(int i=1;i<=n;i++)dpmin[i][0]=a[i];
		for(int j=1;(1<0)maxn=max(slove(i),maxn);
		else maxn=max(slove2(i),maxn);
	}
	printf("%lld\n",maxn);
}

用rmq查询区间最小值,对于正数只需找到满足他是区间中最小值的最大区间(二分分别求左右端点),对于负数则要找到区间和的最小值,二分前缀和求解

你可能感兴趣的:(RMQ,二分,acm,算法)