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. 用 Python 实现每秒处理 120 万次 HTTP 请求

    用 Python 做到每秒处理上百万次 HTTP 请求,可能吗?也许不能,但直到最近,这已成为现实. 很多公司都在为了提升程序的执行性能和降低服务器的运营成本,而放弃 Python 去选择其它编程语言 ...

  2. HTTP错误404.2-Not Found ,模块CgiModule,错误代码0x800704ec

    目录 问题案例 解决问题 问题案例 错误:HTTP 错误 404.2 - Not Found. 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面. 解决问题 网上 ...

  3. HttpRunnerManager平台异步生成及展示代码覆盖率报告

    ant+jacoco+jenkins+HttpRunnerManager代码覆盖率统计平台搭建 实现思路通过jenkins构建,并使用HttpRunnerManager异步实现报告更新与展示. 现在整 ...

  4. Jmeter(一)http接口添加header和cookie

    HTTP信息头管理器在Jmeter的使用过程中起着很重要的作用,通常我们在通过Jmeter向服务器发送http请求(get或者post)的时候,往往后端需要一些验证信息,比如说web服务器需要带过去c ...

  5. kettle部分传输场景应用(每个作业都实验过啦)

    不过都是全量的,没有增量的,增量的需要自行写脚本实现 1.mysql->mysql 2.ftp->mysql(整个文件夹下面读取) 3.hdfs->mysql 4.sftp-> ...

  6. [golang note] 函数定义

    普通函数定义 √ golang函数基本组成:关键字func.函数名.参数列表.返回值.函数体和返回语句. • 语法如下 func 函数名(参数列表) (返回值列表) { // 函数体 } • 示例如下 ...

  7. nginx php fastcgi安装

    CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上. CGI可以用任何一种语言编 ...

  8. vue-cli中的.babelrc文件介绍

    转载自:http://www.cnblogs.com/ye-hcj/p/7071850.html { // 此项指明,转码的规则 "presets": [ //个人认为多此一举 [ ...

  9. CodeForces - 528D Fuzzy Search (FFT求子串匹配)

    题意:求母串中可以匹配模式串的子串的个数,但是每一位i的字符可以左右偏移k个位置. 分析:类似于 UVALive -4671. 用FFT求出每个字符成功匹配的个数.因为字符可以偏移k个单位,先用尺取法 ...

  10. Winter-1-D Max Sum 解题报告及测试数据

    Time Limit:1000MS Memory Limit:32768KB Description Given a sequence a[1],a[2],a[3]......a[n], your j ...