1619 - Feel Good

Time limit: 3.000 seconds

 
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedi-
cated to studying how good or bad days in uent people's memories about some period of life.
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 day was. 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 re ects that good on average period can be greatly spoiled by one very bad day.
Now Bill is planning to investigate his own life and nd the period of his life that had the greatest
value. Help him to do so.
Input
The input will contain several test cases, each of them as described below. Consecutive test cases are
separated by a single blank line.
The rst line of the input le contains
n
| the number of days of Bill's life he is planning to
investigate (1
n
100000). The rest of the le contains
n
integer numbers
a
1
;a
2
;:::;a
n
ranging
from 0 to 10
6
| the emotional values of the days. Numbers are separated by spaces and/or line breaks.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases
will be separated by a blank line.
On the rst line of the output le print the greatest value of some period of Bill's life.
On the second line print two numbers
l
and
r
such that the period from
l
-th to
r
-th day of Bill's
life (inclusive) has the greatest possible value. If there are multiple periods with the greatest possible
value, then print any one of them.
SampleInput
6
3 1 6 4 5 2
SampleOutput
60
3 5
题意:得到max(一个区间的sum*min);
思路:遍历这个序列,得到以该点为最小值的区间;
   单调栈实现;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 100000007
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9;
ll d[N];
ll a[N];
ll l[N];
ll r[N];
ll sum[N];
void init(ll x)
{
ll k=;
a[]=-;
a[x+]=-;
for(ll i=;i<=x;i++)
sum[i]=sum[i-]+a[i];
k=;
d[++k]=;
for(ll i=;i<=x;i++)
{
while(a[d[k]]>=a[i])k--;
l[i]=d[k];
d[++k]=i;
}
k=;
d[++k]=x+;
for(ll i=x;i>=;i--)
{
while(a[d[k]]>=a[i])k--;
r[i]=d[k];
d[++k]=i;
}
}
int main()
{
ll x,y,z,i,t;
int flag=;
while(~scanf("%lld",&x))
{
if(flag)
printf("\n");
flag++;
for(i=;i<=x;i++)
scanf("%lld",&a[i]);
init(x);
ll ans=;
ll ansl=,ansr=;
for(i=;i<=x;i++)
{
ll k=(sum[r[i]-]-sum[l[i]])*a[i];
if(k>ans)
{
ans=k;
ansl=l[i]+;
ansr=r[i]-;
}
}
printf("%lld\n",ans);
printf("%lld %lld\n",ansl,ansr);
}
return ;
}

uva 1619 - Feel Good || poj 2796 单调栈的更多相关文章

  1. [poj 2796]单调栈

    题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include ...

  2. Poj 3250 单调栈

    1.Poj 3250  Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所 ...

  3. poj 2059 单调栈

    题意:求柱状图中最大矩形面积. 单调栈:顾名思义就是栈内元素单调递增的栈. 每次插入数据来维护这个栈,假设当前须要插入的数据小于栈顶的元素,那就一直弹出栈顶的元素.直到满足当前须要插入的元素大于栈顶元 ...

  4. POJ 3044单调栈

    题意: 思路: 单调栈 // by SiriusRen #include <stack> #include <cstdio> using namespace std; stac ...

  5. poj 2082 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<iostream> #include<string> #include<cmath> #include ...

  6. poj 2559 单调栈 ***

    给出一系列的1*h的矩形,求矩形的最大面积. 如图: 题解链接:点我 #include <iostream> #include <cstdio> using namespace ...

  7. poj 2599 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<cstdio> #include<cmath> #include<algorithm> #includ ...

  8. POJ 2796[UVA 1619] Feel Good

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16786   Accepted: 4627 Case T ...

  9. POJ 2796:Feel Good(单调栈)

    http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://ww ...

随机推荐

  1. golang 中的定时器(timer),更巧妙的处理timeout

    今天看到kite项目中的一段代码,发现挺有意思的. // generateToken returns a JWT token string. Please see the URL for detail ...

  2. jquery prop attr

    checked比较特殊,只要设置了属性checked,不管何值都是checked的.例如:<input type="checkbox" checked><inpu ...

  3. 模块讲解----random模块(随机取值)

    导入random模块 import random #查看random的帮助: # help(random) #随机浮点数: #用于生成一个0到1的0 >= n < 1.0的范围值 prin ...

  4. 压力测试sysbench

    sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.目前sysbench代码托管在launchpad上,项目地址:https://launc ...

  5. opencv:vs2015添加了包含目录依然无法打开‘opencv2/core/core.hpp’ 解决方法

    安装环境 win10 vs2015 出错和改错 按网上的教程,配置好opencv后,包括已经把以下内容添加到'包含目录'了: E:\openCV\opencv\build\include E:\ope ...

  6. 无法从U盘启动的解决方案

    联想台式机无法从U盘启动的解决方案 F1进入lenovo bios 选择 StartUp 选项卡 1) 发现 USB FDD 已处于第一项,再把 USB Key 调到启动第二项 2) 把 boot m ...

  7. Mysql 5.7 主从复制

    配置思路1. 修改master和slave的配置文件,使用二进制日志,指定serverid目的是让各自都有了自己的唯一标示,并以二进制文件格式进行交流2. master中创建授权用户,查看二进制日志文 ...

  8. centos7下配置iptables实现外网访问内网服务器

    说明:Centos 7 默认的防火墙是 firewall,安装iptables之前需关闭Firewall 外网机器:外网ip:120.25.71.183内网ip:10.1.1.23 内网机器:内网ip ...

  9. springCloud3---ribbon

    同一份代码,改变端口,就可以启动多个同名但是端口不一样的微服务. 客户端通过nginx来调用后面的多个用户微服务来实现负载均衡,这是服务端负载均衡. 客户端有一个组件,可以知道当前有几个用户微服务的i ...

  10. firewall 防火墙相关

    修改配置文件: /etc/sysconfig/network-scripts/ifcfg-ens33 文件 ONBOOT=no 改为yes 然后重启  service network restart ...