HDU 5662 YJQQQAQ and the function
来源:互联网 发布:淘宝同款图片怎么处理 编辑:程序博客网 时间:2024/06/11 15:47
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 l≤r and r×k≤n , 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(1≤T≤3) ——The number of the test cases. For each test case:
The first line contains an integersn(1≤n≤300,000) .
The second line containsn integers describing the given array A , the i th integer is Ai(1≤Ai≤1,000,000) . Between each two adjacent integers there is a white space separated.
The first line contains an integers
The second line contains
Output
For each test case, the only line contains the only integer that is the maximum value of the function.
Sample Input
132 3 1
Sample Output
10HintWhen 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
- HDU 5662 YJQQQAQ and the function
- HDU 5662 YJQQQAQ and the function
- HDU-5662 YJQQQAQ and the function (枚举&&单调栈)
- hdu5662 YJQQQAQ and the function (单调栈)
- HDU The Euler function
- hdu --- The Euler function
- the function Passing and returning
- HDU 2824 The Euler function
- hdu 2824 The Euler function
- Hdu 2824 The Euler function
- [HDU 2824]The Euler function
- hdu 2824 The Euler function
- hdu 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824 The Euler function
- HDU 2824 The Euler function
- hdu 2824 The Euler function
- HDU 2824 The Euler function
- hihoCoder 1015 kmp算法
- 质数筛 51Nod1441 士兵的数字游戏
- ViewPager显示本地或网络图片的封装
- 4.1 左值到右值的转换 中英文对照(C++标准中文版 ISO/IEC 14882:2014)
- 决策树算法:ID3和C4.5
- HDU 5662 YJQQQAQ and the function
- HDU 1042 N! (大数乘)
- android Html Package机制说明
- 将博客搬至CSDN
- x86汇编--(八)指定位置打印字符串(七改)
- url、src、href定义以及使用区别
- Python之fileinput
- 杭电4505
- [LeetCode]15. 3Sum