【51nod】1564 区间的价值
题解
这个要注意到一个长度大的区间的最大价值一定比长度小的区间的价值要大
然后我们以每个点为最小值,显然区间越长最大值越大,然后我们更新最大区间长度的取值,这个可以用单调栈求这个最小值能更新到的左右端点
最后处理成后缀最大值
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <set>
//#define ivorysi
#define eps 1e-8
#define mo 974711
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define MAXN 100005
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int N,le[MAXN],ri[MAXN],sta[MAXN],top,st[MAXN][20],len[MAXN];
int64 a[MAXN],suf[MAXN];
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
}
template<class T>
void out(T x) {
if(x < 0) {putchar('-');x = -x;}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
void Init() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
for(int i = 2 ; i <= N ; ++i) len[i] = len[i / 2] + 1;
for(int i = 1 ; i <= N ; ++i) {
st[i][0] = a[i];
}
for(int j = 1 ; j <= 19 ; ++j) {
for(int i = 1 ; i <= N ; ++i) {
if(i + (1 << j) - 1 > N) break;
st[i][j] = max(st[i][j - 1],st[i + (1 << j - 1)][j - 1]);
}
}
top = 0;
for(int i = 1 ; i <= N ; ++i) {
while(top > 0 && a[i] < a[sta[top]]) {
ri[sta[top]] = i - 1;
--top;
}
if(!top) le[i] = 1;
else le[i] = sta[top] + 1;
sta[++top] = i;
}
for(int i = 1 ; i <= top ; ++i) ri[sta[i]] = N;
}
void Solve() {
for(int i = 1 ; i <= N ; ++i) {
int k = ri[i] - le[i] + 1;
int64 x = max(st[le[i]][len[k]],st[ri[i] - (1 << len[k]) + 1][len[k]]);
suf[k] = max(suf[k],x * a[i]);
}
for(int i = N ; i >= 1 ; --i) suf[i] = max(suf[i],suf[i + 1]);
for(int i = 1 ; i <= N ; ++i) {
out(suf[i]);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
return 0;
}
【51nod】1564 区间的价值的更多相关文章
- 51nod 1564 区间的价值 | 分治 尺取法
51nod 1564 区间的价值 题面 一个区间的价值是区间最大值×区间最小值.给出一个序列\(a\), 求出其中所有长度为k的子区间的最大价值.对于\(k = 1, 2, ..., n\)输出答案. ...
- 51nod 1674 区间的价值V2(思维+拆位+尺取法)
最近被四区题暴虐... 题意:lyk拥有一个区间. 它规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有数or起来的值的乘积. 例如3个数2,3,6.它们and起来的值为2,or起来的值 ...
- hdu5696 区间的价值
区间的价值 我们定义"区间的价值"为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R-L+1). 现在聪明的杰西想要知道,对于长度为k的区间,最大 ...
- hdu 5696 区间的价值 单调栈+rmq
区间的价值 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- HDU 5696 ——区间的价值——————【线段树、快排思想】
区间的价值 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu5696区间的价值 -- 2016"百度之星" - 初赛(Astar Round2B)
Problem Description 我们定义“区间的价值”为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R−L+1). 现在聪明的杰西想要知道,对于长度为k的区 ...
- HDU5696:区间的价值——题解
http://acm.hdu.edu.cn/showproblem.php?pid=5696 题面是中文的我就不粘贴过来了…… ———————————————————————— 这题垃圾题!!神tm卡 ...
- HDU 5696 区间的价值 暴力DFS
Problem Description 我们定义"区间的价值"为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R−L+1). 现在聪明的杰西想要知 ...
- 1674 区间的价值 V2(分治)
1674 区间的价值 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 lyk拥有一个区间. 它规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有 ...
随机推荐
- Vue入坑教程(一)——搭建vue-cli脚手架
1. Vue简介 详细内容可以参考官网Vue.js 1)兼容性 Vue 不支持 IE8 及以下版本,因为 Vue 使用了 IE8 无法模拟的 ECMAScript 5 特性.但它支持所有兼容 ECMA ...
- Writing your first academic paper
Writing your first academic paper If you are working in academics (and you are if you are working wi ...
- Machine Learning Trick of the Day (1): Replica Trick
Machine Learning Trick of the Day (1): Replica Trick 'Tricks' of all sorts are used throughout machi ...
- The Ph.D. Grind
The Ph.D. Grind A Ph.D. Student Memoir Summary The Ph.D. Grind, a 122-page e-book, is the first know ...
- MapReduce (hive表SequenceFile的结果做输入)、MultipleOutputs和Reduce端迭代iterable的一些说明
很长时间以来一直写hive,嵌套脚本.偶尔写UDF. 最近用Hive的dynamic partition和多路插入做一些事情,很遗憾的结果是非常不稳定,有时能成功,有时失败.(可能是因为hive版本 ...
- 英雄无敌3开源引擎vcmi的编译安装
TAGS: Heroes3, vcmi, opensourceDATE: 2013-08-23 vcmi是什么? vcmi 是经典的 SLG 英雄无敌3 的开源游戏引擎.原来的英雄无敌3只能在Wind ...
- $("节点名").html("字符串")和$("节点名").text("字符串")区别
1. 经过html方法: $(".js_info").html("~!`@#$%^& ";'<>\=/-!·#¥%…&*()—+|` ...
- const与指针
C++中const与指针 1.常指针: ; int * const pInt = &x; 其中PInt是常指针,pInt的值无法改变,但其指向的内容可以改变. 2.指向常量的指针 有两种写法: ...
- java所搜引擎slor学习笔记(一)
java搜索引擎有很多,比较熟悉的就是slor和lucene. luncene: 概念:全文检索是计算机程序通过扫描文章中的每一个词,对每一个词建立一个索引,指明该词在文章中出现的次数和位置.当用户查 ...
- swagger学习
https://segmentfault.com/a/1190000010144742 https://segmentfault.com/a/1190000014775124 https://blog ...