cf 547B. Mike and Feet dp
题意:
n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1
对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度
求:for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.
对于每一个矩阵,我们先求出这个矩阵的l,r
l表示这个矩阵左边最靠近它的小于它的矩阵的下标
r表示这个矩阵右边最靠近它的小于它的矩阵的下标
即在区间(l,r)内,strength 等于这个矩阵的高度
注意:不包括l,r这2个矩阵
求l,r的值可以用dp
求完l,r后只需要把这些矩阵按照高度小到大sort一遍,
然后遍历一遍,不断更新ans数组即可
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; const int MAXN = +; int ans[MAXN];
struct Node
{
int hei,l,r;
};
Node node[MAXN]; bool cmp(Node x,Node y)
{
return x.hei < y.hei;
} void solve()
{
int n;
scanf("%d",&n);
n++;
for(int i=;i<n;i++){
scanf("%d",&node[i].hei);
} node[].hei = ;
node[n].hei = ; for(int i=;i<n;i++){
node[i].l = i - ;
while(i > && node[node[i].l].hei >= node[i].hei){
node[i].l = node[node[i].l].l;
}
}
for(int i=n-;i>;i--){
node[i].r = i + ;
while(i < n && node[node[i].r].hei >= node[i].hei){
node[i].r = node[node[i].r].r;
}
} memset(ans,-,sizeof ans); sort(node+,node+n,cmp); for(int i=;i<n;i++){
int pos = node[i].r - node[i].l - ;
ans[pos] = max(ans[pos],node[i].hei);
} for(int i=n-;i>;i--){
ans[i] = max(ans[i],ans[i+]);
} for(int i=;i<n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-]); return ;
} int main()
{
solve();
return ;
}
cf 547B. Mike and Feet dp的更多相关文章
- codeforces 547B. Mike and Feet 单调栈
题目链接 用单调栈计算出一个数字, 左边第一个比他小的数字的位置, 右边比第一个他小的数字的位置, 然后len = r[i] - l[i] +1. ans[len] = max(ans[len], a ...
- Codeforces 547B. Mike and Feet[单调栈/队列]
这道题用单调递增的单调栈维护每个数能够覆盖的最大区间即可. 对于 1 2 3 4 5 4 3 2 1 6 这组样例, 1能够覆盖的最大区间是10,2能够覆盖的最大区间是7,以此类推,我们可以使用单 ...
- Mike and Feet(CF 547B)
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF #305(Div.2) D. Mike and Feet(数学推导)
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CF Mike and Feet (求连续区间内长度为i的最小值)单调栈
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈
B. Mike and Feet Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CF 983B XOR-pyramid(区间dp,异或)
CF 983B XOR-pyramid(区间dp,异或) 若有一个长度为m的数组b,定义函数f为: \(f(b) = \begin{cases} b[1] & \quad \text{if } ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- Get access to Servlet
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class LoginServlet extend ...
- 越狱Season 1- Episode 16
Season 1, Episode 16 -Burrows:Don't be. It's not your fault. 不要,不是你的错 -Fernando: Know what I like? 知 ...
- Ghost的相关问题
一些和Ghost使用有关的问题,记录在这里. 1,有时候使用ghost恢复,发现最后一步选择驱动器是灰色的,这是因为备份文件有些是用Disk模式,有些使用partition模式,所有恢复的时候如果其中 ...
- MySQL root密码重置 报错:mysqladmin: connect to server at 'localhost' failed的解决方案
===========================================================二,忘记本地root的登录密码解决过程:1.编辑/mysql/my.ini在[my ...
- caffe:编译时提示:unsupported GNU version! gcc versions later than 4.9 are not supported!
NVCC src/caffe/solvers/adam_solver.cuIn file included from /usr/local/cuda/include/cuda_runtime.h:76 ...
- java .net compartion
1, http://www-01.ibm.com/software/smb/na/J2EE_vs_NET_History_and_Comparison.pdf http://stackoverflow ...
- Hadoop SPARK 环境搭建
http://www.linuxidc.com/Linux/2015-02/113486.htm http://www.cnblogs.com/lijingchn/p/5574476.html htt ...
- lua for循环
<转自网络,仅供学习> for循环是一个循环控制结构,可以有效地编写需要执行的特定次数的循环. 语法 Lua编程语言的for循环的语法是: for init,max/min value, ...
- Heap Only Tuples (HOT)
Introduction ------------ The Heap Only Tuple (HOT) feature eliminates redundant index entries and a ...
- Avoiding PostgreSQL database corruption
TL;DR: Don't ever set fsync=off, don't kill -9 the postmaster then deletepostmaster.pid, don't run P ...