codeforces 547B【单调栈】
题意:
有一个长度为n的序列,序列有长度为1...n的连续子序列,
一个连续子序列里面最小的值称作这个子序列的子序列的strength,
要求出每种长度的连续子序列的最大的strength。
思路:
以当前位置为最小值,向两边延伸。
那我就能知道这个位置作为最小值时长度。
具体思路忘了。。。
给出几组数据希望能有启发?
/*
10
1 2 3 4 5 4 3 2 1 6
10
100000 99999 99998 99997 99996 99995 99994 99993 99992 99991
10
1 2 3 4 5 6 7 8 9 10
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+10;
struct asd
{
int left,right,w;
};
int num[N],n,h[N];
stack<asd>q;
int main()
{
asd now,nex;
int temp,tmp;
while(!q.empty())
q.pop();
memset(num,0,sizeof(num));
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d",&h[i]);
num[1]=max(num[1],h[1]);
now.left=1;
now.right=1;
now.w=h[1];
q.push(now);
bool flag;
for(int i=2; i<=n; i++)
{
now.left=1;
now.right=1;
now.w=h[i];
while(!q.empty()&&q.top().w>h[i])
{
nex=q.top();
q.pop();
now.left+=nex.left;
temp=nex.right+nex.left-1;
num[temp]=max(num[temp],nex.w);
if(!q.empty())
q.top().right+=nex.right;
}
q.push(now);
}
flag=false;
while(!q.empty())
{
nex=q.top();
q.pop();
temp=nex.right+nex.left-1;
num[temp]=max(num[temp],nex.w);
if(!q.empty())
q.top().right+=nex.right;
}
temp=num[n];
for(int i=n;i>=1;i--)
{
if(num[i]<=temp)
num[i]=temp;
else
temp=num[i];
}
for(int i=1;i<=n;i++)
printf("%d ",num[i]);
return 0;
}
codeforces 547B【单调栈】的更多相关文章
- CodeForces 548D 单调栈
Mike and Feet Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Subm ...
- Discrete Centrifugal Jumps CodeForces - 1407D 单调栈+dp
题意: 给你n个数hi,你刚开始在第1个数的位置,你需要跳到第n个数的位置. 1.对于i.j(i<j) 如果满足 max(hi+1,-,hj−1)<min(hi,hj) max(hi,hj ...
- 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,以此类推,我们可以使用单 ...
- Codeforces 1107G Vasya and Maximum Profit [单调栈]
洛谷 Codeforces 我竟然能在有生之年踩标算. 思路 首先考虑暴力:枚举左右端点直接计算. 考虑记录\(sum_x=\sum_{i=1}^x c_i\),设选\([l,r]\)时那个奇怪东西的 ...
- Codeforces 802I Fake News (hard) (SA+单调栈) 或 SAM
原文链接http://www.cnblogs.com/zhouzhendong/p/9026184.html 题目传送门 - Codeforces 802I 题意 求一个串中,所有本质不同子串的出现次 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- 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 1107G Vasya and Maximum Profit 线段树最大子段和 + 单调栈
Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of t ...
- codeforces 817 D. Imbalanced Array(单调栈+思维)
题目链接:http://codeforces.com/contest/817/problem/D 题意:给你n个数a[1..n]定义连续子段imbalance值为最大值和最小值的差,要你求这个数组的i ...
随机推荐
- LeetCode 017 4Sum
[题目] Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d ...
- LeetCode:删除链表中的节点【203】
LeetCode:删除链表中的节点[203] 题目描述 删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val ...
- html--<meta>设置缓存
html头文件设置常用之<meta>设置缓存 <meta http-equiv="pragma" content="no-cache"&g ...
- 3D 图片播放焦点图插件Adaptor
在线演示 本地下载
- Linux系统资源查看与设置
/proc/sys/fs/file-max = 65536 /proc/sys/net/ipv4/tcp_fin_timeout = 15 /proc/sys/net/ipv4/tcp_tw_recy ...
- 什么是XXX
1.什么事框架 框架式一组程序的集合,包含了一系列的最佳实践,作用是 解决某个领域的问题. 当我们使用某个框架时,其实是把一系列JAR包加载到CLASSPATH路径中,实际上是获得了JAR中所有对J ...
- <再看TCP/IP第一卷>关于链路层的知识细节及相关协议
在TCP/IP协议族中,链路层的主要有三个目的: (1)为IP模块发送和接受数据报 (2)为ARP模块发送ARP请求和接受ARP应答 (3)为RARP发送RARP请求和接受RARP应答 TCP/IP支 ...
- jQuery选项卡tabulous
jQuery选项卡tabulous,jQuery,选项卡,tab标签切换代码,扁平设计,jQuery选项卡tabulous是一款支持Scale.Slide.Scale Up.Flip等效果jquery ...
- RQNOJ 328 炮兵阵地:状压dp
题目链接:https://www.rqnoj.cn/problem/328 题意: 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队. 一个N*M的地图由N行M列组成(N≤100,M≤10), ...
- CodeForces 547E:Mike and Friends(AC自动机+DFS序+主席树)
What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercas ...