hdu5662 YJQQQAQ and the function (单调栈)
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.
number of the test cases. For each test case:
The first line contains an integers n(1≤n≤300,000).
The second line contains n integers
describing the given array A,
the ith
integer is Ai(1≤Ai≤1,000,000).
Between each two adjacent integers there is a white space separated.
3
2 3 1
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<bitset>
#include<algorithm>
using namespace std;
#define lth th<<1
#define rth th<<1|1
typedef long long ll;
typedef long double ldb;
#define inf 99999999
#define pi acos(-1.0)
#define maxn 300050
int b[maxn],a[maxn];
ll sum[maxn];
int L[maxn],R[maxn];
int q[511111][2];
int main()
{
int n,m,i,j,T,l,r,k;
int front,rear;
ll ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
ans=0;
for(k=1;k<=n;k++){
int tot=0;
sum[0]=0;
for(i=1;i*k<=n;i++){
tot++;
b[tot]=a[i*k];
sum[tot]=sum[tot-1]+b[tot];
}
front=1,rear=0;
for(i=1;i<=tot;i++){
while(front<=rear && q[rear][0]>=b[i] ){
rear--;
}
if(rear==0){
L[i]=1;
}
else{
L[i]=q[rear][1]+1;
}
rear++;
q[rear][0]=b[i];q[rear][1]=i;
}
front=1,rear=0;
for(i=tot;i>=1;i--){
while(front<=rear && q[rear][0]>=b[i] ){
rear--;
}
if(rear==0){
R[i]=tot;
}
else{
R[i]=q[rear][1]-1;
}
rear++;
q[rear][0]=b[i];q[rear][1]=i;
ans=max(ans,(sum[R[i] ]-sum[L[i]-1 ])*b[i]*(int)sqrt((double)k) );
}
}
printf("%lld\n",ans);
}
return 0;
}
hdu5662 YJQQQAQ and the function (单调栈)的更多相关文章
- 2016 大连网赛---Function(单调栈)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5875 Problem Description The shorter, the simpl ...
- HDU 5875 Function (线段树+gcd / 单调栈)
题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对数字b取模时:如果a<b,则等于原数,否则a会变小至少一半. ...
- HDU 5875 H - Function 用单调栈水过了
http://acm.hdu.edu.cn/showproblem.php?pid=5875 单调栈,预处理to[i]表示第一个比a[i]小的数字,一直跳就可以. 这题是数据水而已. 这里学习下单调栈 ...
- Function:凸包,单调栈,题意转化,单峰函数三分,离线处理
很难啊啊啊!!! bzoj5380原题,应该可以粘题面. 问题转换: 有一个n列1e9行的矩阵,每一列上都写着相同的数字Ai. 你从位置(x,y)出发每一步可以向左上方或左方走一步,最后走到第一行. ...
- poj2559 Largest Rectangle in a Histogram(单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- Codeforces #123D: 后缀数组+单调栈
D. String You are given a string s. Each pair of numbers l and r that fulfill the condition 1 ≤ ...
- hdu 5875(单调栈)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- 【BZOJ3238】差异(后缀数组,单调栈)
题意: 思路:显然len(t[i])+len(t[j])这部分的和是一定的 那么问题就在于如何快速求出两两之间lcp之和 考虑将它们排名后用SA可以很方便的求出lcp,且对答案没有影响,因为形式都是数 ...
- php实现包含min函数的栈(这个题目用另外一个栈做单调栈的话时间复杂度会低很多)
php实现包含min函数的栈(这个题目用另外一个栈做单调栈的话时间复杂度会低很多) 一.总结 这个题目用另外一个栈做单调栈的话时间复杂度会低很多 二.php实现包含min函数的栈 题目描述 定义栈的数 ...
随机推荐
- (二)数据源处理6-excel数据转换实战(下)
将结果的所有数据整理如下: {'api_case_01': [{'测试用例编号': 'api_case_01', '测试用例名称': '获取access_token接口测试', '用例执行': '是' ...
- mysql—make_set函数
使用格式:MAKE_SET(bits,str1,str2,-) 1 返回一个设定值(含子字符串分隔字符串","字符),在设置位的相应位的字符串.str1对应于位0,str2到第1位 ...
- ctfhub技能树—信息泄露—PHPINFO
打开靶机 查看页面,是PHP info界面 只有这一个页面,查找一下有没有flag 拿到flag 浅谈ctf中phpinfo需要关注的点(转自先知社区) 1 https://xz.aliyun.com ...
- ctfshow—web—web签到题
打开靶机,发现只有一句话 查看源码 发现一段字符串,猜是base64加密 拿到flag
- 关掉IE提示“当前安全设置会使计算机有风险”
我们先来看一下IE浏览器出现的提示窗口,该窗口位于最顶端,不点击设置的话,无法进行下一步的操作. 这时我们点击开始按钮 ,在弹出菜单中选择"运行"菜单项. 在打开的Windows运 ...
- 显示HDFS中指定的文件读写权限、大小、创建时间、路径等信息。
1 import org.apache.hadoop.fs.*; 2 import java.text.SimpleDateFormat; 3 public class D_ReadFileStatu ...
- How to Gracefully Close Channels
小结: 1. When a goroutine sends a value to a channel, we can view the goroutine releases the ownership ...
- win api 窗口操作-窗口置顶与寻找与激活
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos https://docs.micr ...
- 获取当前文件路径 import 原理 一般把模块组成的集合称为包(package)
获取当前文件路径 testpath.py import sysprint(sys.path) [root@d mapReduceLog]# python testpath.py['/data/mapR ...
- virtualenv安装和配置
安装命令 命令执行结束 配 执行命令:virtualenv testvir 执行完成:会在当前目录下生成如下文件夹 进入到testvir目录 进入Scripts目录: 进入虚拟环境:执行 activa ...