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. Android 查看自己的keystore的别名及相关信息

    1.在DOS窗口下进入自己的keystore所在位置,输入 keytool -list  -v -keystore xxxx.keystore -storepass 密码 xxxx.keystore是 ...

  2. windows中根据进程PID查找进程对象过程深入分析

    这里windows和Linxu系列的PID 管理方式有所不同,windows中进程的PID和句柄没有本质区别,根据句柄索引对象和根据PID或者TID查找进程或者线程的步骤也是一样的.   句柄是针对进 ...

  3. python常见模块之os模块

    os模块是python系统与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前 ...

  4. Flask上下文管理

    一.一些python的知识 1.偏函数 def add(x, y, z): print(x + y + z) # 原本的写法:x,y,z可以传任意数字 add(1,2,3) # 如果我要实现一个功能, ...

  5. 002-shell变量定义、使用、字符串、数组、注释

    一.变量定义 定义变量时,变量名不加美元符号($) name="lhx" 注意,变量名和等号之间不能有空格.同时,变量名的命名须遵循如下规则: 命名只能使用英文字母,数字和下划线, ...

  6. nodejs 视频教程《一起学nodejs》

    一起学nodejs 讲师:   matthew vscode+nodejs4.6 http://list.youku.com/albumlist/show/id_27966955.html?spm=a ...

  7. 等待事件对应的p1,p2,p3含义

    Oracle 10g v$session视图中不同等待事件对应的p1,p2,p3的含义也不同,我们不可能记住所有等待事件对应的p1,p2,p3的含义. 可以通过查询V$EVENT_NAME知道每个等待 ...

  8. (转)CreateThread与_beginthread,内存泄漏为何因(原帖排版有些不好 ,所以我稍微整理下)

            在写c++代码时,一直牢记着一句话:决不应该调用CreateThread. 应该使用Visual   C++运行时库函数_beginthreadex.好像CreateThread函数就 ...

  9. python3 用requests 保存网页以及BeautifulSoup保存图片,并且在本地可以正常显示文章的内容和图片

    用requests 模块做了个简单的爬虫小程序,将博客的一篇文章以及图片保存到本地,文章格式存为'.html'.当文章保存到本地后,图片的连接可能是目标站点的绝对或者相对路径,所以要是想在本地也显示图 ...

  10. Embedding SQLite in a c programm

    Embedding SQLite in a c programm        The following program demonstrates how to embed SQLite into ...