HDU 5662 YJQQQAQ and the function

16 篇文章 0 订阅
Problem Description
YJQQQAQ has an array  A  of length  n . He defines a function  fl,r,k  where  l,r,k  are positive integers that satisfies  lr  and  r×kn , and the value of the function equals to  p×q×k  where  p  equals to the sum value of  Al×k,A(l+1)×k,...,Ar×k  and  q  equals to the minimal value of them. YJQQQAQ wants to choose the positive integers  l,r,k  carefully to maximize the value of the function.
 

Input
The first line contains an integer  T(1T3) ——The number of the test cases. For each test case:
The first line contains an integers  n(1n300,000) .
The second line contains  n  integers describing the given array  A , the  i th integer is  Ai(1Ai1,000,000) . Between each two adjacent integers there is a white space separated.
 

Output
For each test case, the only line contains the only integer that is the maximum value of the function.
 

Sample Input
  
  
1 3 2 3 1
 

Sample Output
  
  
10
Hint
When and only when $l=1,r=2,k=1$, the value of the function is the maximum.
原来有种东西叫做单调栈
#pragma comment(linker, "/STACK:1024000000,1024000000") 
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
typedef __int64 LL;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;
int T, n, m, a[maxn], b[maxn], l[maxn], r[maxn];
LL sum[maxn];

int main() {
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		LL ans = 0;
		for (int i = 1; i <= n; i++)
		{
			sum[0] = m = 0;
			for (int j = 1; j*i <= n; j++)
			{
				b[++m] = a[j*i];
				sum[m] = sum[m - 1] + b[m];
			}
			stack<int> p;
			for (int j = 1; j <= m; j++)
			{
				while (!p.empty() && b[p.top()] > b[j]) r[p.top()] = j - 1, p.pop();
				p.push(j);
			}
			while (!p.empty()) r[p.top()] = m, p.pop();
			for (int j = m; j; j--)
			{
				while (!p.empty() && b[p.top()] > b[j]) l[p.top()] = j + 1, p.pop();
				p.push(j);
			}
			while (!p.empty()) r[p.top()] = 1, p.pop();
			for (int j = 1; j <= m; j++) ans = max(ans, (sum[r[j]] - sum[l[j] - 1])*b[j] * (int)sqrt(i));
		}
		printf("%I64d\n", ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值