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. 进程Process之join、daemon(守护)、terminate(关闭)

    一.Process 参数介绍: 1 group参数未使用,值始终为None 2 target表示调用对象,即子进程要执行的任务 3 args表示调用对象的位置参数元组,args=(1,2,'a',) ...

  2. freemarker学习#1

    在工作的过程中遇到了.ftl文件.打开发现里面是一些类似于html的代码,非常好奇这是一种什么样的文件,于是去网上搜了一下,了解到.ftl是Freemarker模板的文件后缀名.将问题转移到了Free ...

  3. LocalActivityManager与ActivityGroup

    Helper class for managing multiple running embedded activities in the same process. This class is no ...

  4. SIP中的 session, dialog 及 transaction 的解释

    http://stackoverflow.com/questions/35133331/difference-between-session-dialog-and-transaction-in-sip ...

  5. (转)Linux下配置tomcat+apr+native应对高并发

    摘要:在慢速网络上Tomcat线程数开到300以上的水平,不配APR,基本上300个线程狠快就会用满,以后的请求就只好等待.但是配上APR之后,Tomcat将以JNI的形式调用Apache HTTP服 ...

  6. Push h.264 rawdata to rtmp server

    Push h.264 rawdata to rtmp server /* The MIT License (MIT) Copyright (c) 2013-2015 SRS(ossrs) Permis ...

  7. py-统计一个矩阵中每一列的非0数的个数

    1.文件类型类似于这样: 不过数据量比这个要更大一点. 2.对应上述数据的运行结果: import matplotlib.pyplot as plt with open('test.txt') as ...

  8. debian flam3 依赖文件

    https://packages.debian.org/stable/graphics/flam3     package names   descriptions   source package ...

  9. Jenkins--持续集成服务器

    1.持续集成: 1.1概念 持续集成,Continuous integration ,简称CI. 集成:我们所有项目的代码都是托管在SVN服务器上.每个项目都要有若干个单元测试,并有一个所谓集成测试. ...

  10. IOS系统推送原理

    IOS推送大致原理如下图 1.Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provider可以理解为服务端[消息的发起者]): 2. ...