poj 2796 Feel Good 单调队列
|
Feel Good
Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent 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 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 The first line of the input contains n - the number of days of Bill's life he is planning to investigate(1 <= n <= 100 000). The rest of the file contains n integer numbers a1, a2, ... an ranging from 0 to 106 - the emotional values of the days. Numbers are separated by spaces and/or line breaks.
Output Print the greatest value of some period of Bill's life in the first line. And 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.
Sample Input 6 Sample Output 60 Source |
[Submit] [Go Back] [Status] [Discuss]
/*
题意:10^5个数字,求max { 区间[ ] * 该区间最小值 };
解决思路:
找区间最小值,如果能够求出其长度,那么就可以扫一遍解决。
关键在于找区间最小值。
而且存在一种情况,同一个值,会是许多区间的最小值。
所以,转化一下,求每一个i为最小值的时候,能到到达的最远位置。 */ #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int a[],b[];
__int64 s[];
int L[],R[];
typedef struct
{
int num;
int rp;
}Queue;
Queue q[],tmp; int main()
{
int n,i;
int head,tail,Num,l,r,lx,rx;
__int64 hxl,tom;
while(scanf("%d",&n)>)
{
for(i=,s[]=;i<=n;i++)
{
scanf("%d",&a[i]);
b[n-i+]=a[i];
s[i]=s[i-]+a[i];
}
memset(L,-,sizeof(L));
memset(R,-,sizeof(R));
head=;tail=-;
for(i=;i<=n;i++)
{
tmp.num=i;
tmp.rp=a[i];
while( head<=tail && q[tail].rp>tmp.rp )
{
if( R[q[tail].num]==-)
{
R[q[tail].num]= i - q[tail].num-;
}
tail--;
}
q[++tail]=tmp;
}
while( head<=tail )
{
Num=q[tail].num-q[head].num;
if( R[q[head].num]==-)
{
R[q[head].num]=Num;
}
head++;
}
head=;tail=-;
for(i=;i<=n;i++)
{
tmp.num=i;
tmp.rp=b[i];
while( head<=tail && q[tail].rp>tmp.rp )
{
Num=n-q[tail].num+;
if( L[Num]==-)
L[Num]= i - q[tail].num-;
tail--;
}
q[++tail]=tmp;
}
while( head<=tail )
{
Num=n-q[head].num+;
if( L[Num]==-)
{
L[Num]=q[tail].num-q[head].num;
}
head++;
}
for(tom=-,i=;i<=n;i++)
{
l=i-L[i];
r=i+R[i];
hxl=(s[r]-s[l-])*a[i];
if( hxl>tom)
{
tom=hxl;
lx=l;
rx=r;
}
}
printf("%I64d\n%d %d\n",tom,lx,rx);
}
return ;
}
poj 2796 Feel Good 单调队列的更多相关文章
- POJ 2823 Sliding Window + 单调队列
一.概念介绍 1. 双端队列 双端队列是一种线性表,是一种特殊的队列,遵守先进先出的原则.双端队列支持以下4种操作: (1) 从队首删除 (2) 从队尾删除 (3) 从队尾插入 (4) ...
- poj 2823 Sliding Window (单调队列入门)
/***************************************************************** 题目: Sliding Window(poj 2823) 链接: ...
- poj 1821 Fence(单调队列优化DP)
poj 1821 Fence \(solution:\) 这道题因为每一个粉刷的人都有一块"必刷的木板",所以可以预见我们的最终方案里的粉刷匠一定是按其必刷的木板的顺序排列的.这就 ...
- POJ 2823 滑动窗口 单调队列模板
我们从最简单的问题开始: 给定一个长度为N的整数数列a(i),i=0,1,...,N-1和窗长度k. 要求: f(i) = max{a(i-k+1),a(i-k+2),..., a(i)},i = 0 ...
- POJ 3709 K-Anonymous Sequence (单调队列优化)
题意:给定一个不下降数列,一个K,将数列分成若干段,每段的数字个数不小于K,每段的代价是这段内每个数字减去这段中最小数字之和.求一种分法使得总代价最小? 思路:F[i]表示到i的最小代价.f[i]=m ...
- POJ 2823 滑动窗口 单调队列
https://vjudge.net/problem/POJ-2823 中文:https://loj.ac/problem/10175 题目 给一个长度为 $N$ 的数组,一个长为 $K$ 的滑动窗体 ...
- POJ 2823 Sliding Window (单调队列)
单调队列 加了读入挂比不加更慢.... 而且这份代码要交c++ 有大神G++跑了700ms..... orzorzorz #include<iostream> #include<cs ...
- poj 3162 树DP+单调队列
http://acm.hust.edu.cn/vjudge/problem/11552 http://blog.csdn.net/woshi250hua/article/details/7727677 ...
- poj 2823 Sliding Windows (单调队列+输入输出挂)
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 73426 Accepted: 20849 ...
随机推荐
- npm 查看express版本
npm list 名称 eg: npm list express
- SAE实践——创建新应用开启MySQL服务
1. 创建SAE应用 当创建完成SAE账户之后,即可创建SAE应用.点击创建新应用按钮,创建一个新的SAE 应用 阅读提示信息,等待五秒,点继续创建. 填写应用信息完成创建.可选择PHP5.3和空应用 ...
- gitLab创建自己的私有库
一.创建私有库的流程简介 创建一个项目,留着后面的流程3制作私有库 在可以创建私有库的地方创建一个code repository, code repository是代码仓库,我们把代码上传到这个仓库. ...
- Objective-C Associated Objects 的实现原理
我们知道,在 Objective-C 中可以通过 Category 给一个现有的类添加属性,但是却不能添加实例变量,这似乎成为了 Objective-C 的一个明显短板.然而值得庆幸的是,我们可以通过 ...
- 「Neerc2016」Expect to Wait
题目描述 ls最近开了一家图书馆,大家听说是ls开的,纷纷过来借书,自然就会出现供不应求的情况, 并且借书的过程类 似一个队列,每次有人来借书就将它加至队尾,每次有人来还书就把书借给队头的若干个人,定 ...
- UVA_11922 Permutation Transformer 【splay树】
一.题目 UVA11922 二.分析 为什么会有伸展树? 伸展树与AVL的区别除了保持平衡的方式不同外,最重要的是在每次查找点时,让该点旋转到根结点,这里可以结合计算机里的局部性原理思考. 伸展树有什 ...
- Windows网络服务渗透攻击分类
网络服务渗透攻击分为三类 一.针对于windows系统自带的网络服务的渗透攻击 1.针对于NetBIOS的攻击 NetBIOS以运行在TCP/IP系统中的NBT协议来实现,具体包括在UDP的137端口 ...
- python爬虫常用之Scrapy 简述
一.安装 pip install scrapy. 如果提示需要什么包就装什么包 有的包pip安装不起,需要自己下载whl文件进行安装. 二.基本的爬虫流程 通用爬虫有如下几步: 构造url --> ...
- (转)jieba中文分词的.NET版本:jieba.NET
简介 平时经常用Python写些小程序.在做文本分析相关的事情时免不了进行中文分词,于是就遇到了用Python实现的结巴中文分词.jieba使用起来非常简单,同时分词的结果也令人印象深刻,有兴趣的可以 ...
- 翻译:WebAssembly简介:我们为什么要关心这个技术?
原文: https://tomassetti.me/introduction-to-webassembly/ WebAssembly简介:我们为什么要关心这个技术? 在对抗js的伟大战斗中有 ...


