POJ - 2796 Feel Good 单调递增栈+前缀和
Feel Good
A new idea Bill has recently developed assigns a non-negative integer value to each day of human life.
Bill calls this value the emotional value of the day. The greater the emotional value is, the better the daywas. Bill suggests that the value of some period of human life is proportional to the sum of the emotional values of the days in the given period, multiplied by the smallest emotional value of the day in it. This schema reflects that good on average period can be greatly spoiled by one very bad day.
Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.
Input
Output
Sample Input
6
3 1 6 4 5 2
Sample Output
60
3 5 单调递增栈,遍历最小值,找左右两端点,前缀和求出区间和×最小值,更新最大解。
#include<stdio.h>
#include<string.h>
#include<stack>
using namespace std;
int main()
{
int n,i;
long long max;
long long a[],b[],l[],r[];
stack<int> s;
scanf("%d",&n);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(l,,sizeof(l));
memset(r,,sizeof(r));
for(i=;i<=n;i++){
scanf("%lld",&a[i]);
b[i]+=b[i-]+a[i];
}
for(i=;i<=n;i++){
while(s.size()&&a[s.top()]>=a[i]) s.pop();
l[i]=s.size()==?:(s.top()+);
s.push(i);
}
while(s.size()) s.pop();
for(i=n;i>=;i--){
while(s.size()&&a[s.top()]>=a[i]) s.pop();
r[i]=s.size()==?n:(s.top()-);
s.push(i);
}
max=;
int ll=,rr=;
for(i=;i<=n;i++){
if((b[r[i]]-b[l[i]-])*a[i]>max){
max=(b[r[i]]-b[l[i]-])*a[i];
ll=l[i];
rr=r[i];
}
}
printf("%lld\n%d %d\n",max,ll,rr);
return ;
}
POJ - 2796 Feel Good 单调递增栈+前缀和的更多相关文章
- poj 2796 Feel Good单调栈
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20408 Accepted: 5632 Case T ...
- poj 2796 Feel Good 单调栈区间问题
Feel Good 题意:给你一个非负整数数组,定义某个区间的参考值为:区间所有元素的和*区间最小元素.求该数组中的最大参考值以及对应的区间. 比如说有6个数3 1 6 4 5 2 最大参考值为6,4 ...
- QDUOJ LC的课后辅导 单调递增栈
LC的课后辅导 发布时间: 2015年9月19日 21:42 时间限制: 1000ms 内存限制: 256M 描述 有一天,LC给我们出了一道题,如图: 这个图形从左到右由若干个 宽为1 高不 ...
- poj 2796 Feel Good 单调队列
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8753 Accepted: 2367 Case Ti ...
- POJ 2796 Feel Good 【单调栈】
传送门:http://poj.org/problem?id=2796 题意:给你一串数字,需要你求出(某个子区间乘以这段区间中的最小值)所得到的最大值 例子: 6 3 1 6 4 5 2 当L=3,R ...
- POJ 2796:Feel Good(单调栈)
http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://ww ...
- POJ 2796:Feel Good 单调栈
题目,给定一个数列,n <= 1e5 .要求找出一个区间,使得其内区间最小值 * 区间总和的值最大,要求输出区间. 首先先维护一个单调递增的栈,同时记录一个lef值表示:lef[i]表示当前栈内 ...
- 线段树+单调栈+前缀和--2019icpc南昌网络赛I
线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...
- POJ 3415 后缀数组+单调栈
题目大意: 给定A,B两种字符串,问他们当中的长度大于k的公共子串的个数有多少个 这道题目本身理解不难,将两个字符串合并后求出它的后缀数组 然后利用后缀数组求解答案 这里一开始看题解说要用栈的思想,觉 ...
随机推荐
- 算法NB三人组
#快速排序-除了python自带的sort排序模块之外就这个最好用,只需会这个就行,其他的排序了解就好,能用冒泡,插入..的都可以用快排快速实现 import random from timewrap ...
- 谈谈 T 型人才
谈谈 T 型人才 昨天的图片发模糊了,正好我把这个话题展开聊一聊吧.这个话题是关于复合型人才的,我把它称作 T 型人才. 「全栈」工程师 前一段时间,「全栈」工程师的概念很火,不过大多数时候,「全 ...
- RecyclerView的那点事儿
RecyclerView 控件简单介绍 ListView的升级版 LinearLayoutManager GridLayoutManager StaggeredGridLayoutManager 定制 ...
- XML 解析错误:找不到根元素
大家在开发web项目的过程中,可能会遇到“XML 解析错误:找不到根元素”这么一个问题,引起这个问题的原因可能有很多种,在这儿我只是跟大家分享一下我遇到一种情况. 1.项目背景描述 extjs 结合a ...
- 原来浏览器原生支持JS Base64编码解码 outside of the Latin1 range
原来浏览器原生支持JS Base64编码解码 « 张鑫旭-鑫空间-鑫生活 https://www.zhangxinxu.com/wordpress/2018/08/js-base64-atob-bto ...
- Find out when memory leaks are a concern and how to prevent them
Handling memory leaks in Java programs Find out when memory leaks are a concern and how to prevent t ...
- ORACLE函数之单行转换函数
1 ASCIISTR 格式:ASCIISTR(C) 说明:将字符串C转换为ASCII字符串,即将C中的ASCII字符保留不变,但非ASCII字符则以ASCII表示返回 举例: ...
- php date之间的相互转换
字符串转成date $str =date("Y-m-d H:i:s",strtotime("2011-12-12 14:23:01")); echo $str; ...
- RecyclerView 可以与CollapsingToolbarLayout一起使用
Item 布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...
- ZOJ - 3956 Course Selection System 【01背包变形】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意 给出N组Hi Ci 然后 要选出若干个 使得 这个式 ...