topic
train of thought
This question is an analogy of this question , so it is recommended to take a look first.
This question is actually the same question, except that an array mn[][] is missing, and the final answer function after preprocessing has also changed a bit.
the code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int s[10000001],n,q,a[10000001],mx[100001][101],t,x,y,ans;
void zynb()
{
int r = log2(n);
for(int i = 1; i <= r; i++)
for(int j = 1; s[i] + j - 1 <= n; j++)
mx[j][i] = min(mx[j][i - 1],mx[j + s[i - 1]][i - 1]);
}
int weqsb(int x,int y)
{
int r = log2(y - x + 1);
int t1 = min(mx[x][r],mx[y - s[r] + 1][r]);
return (y - x + 1) * t1;
}
signed main()
{
s[0] = 1;
for(int i = 1; i <= 15; i++) s[i] = s[i - 1] * 2;
scanf("%lld",&n);
for(int i = 1; i <= n; i++)
{
scanf("%lld",&t);
mx[i][0] = t;
}
zynb();
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
ans = max(ans,weqsb(i,j));
printf("%lld",ans);
return 0;
}