洛谷 P2947 [USACO09MAR]向右看齐Look Up
题目
思路
单调栈裸题
\(Code\)
#include<stack>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#define MAXN 100001
#define rr register
using namespace std;
int n,ans[MAXN];
struct mu{
int num,h;
}mumumu[MAXN];
stack<mu> sss;
inline int read(){
int x=0;bool f=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return f?-x:x;
}
int main(){
n=read();
for(rr int i=1;i<=n;++i){
mumumu[i].num=i;
mumumu[i].h=read();
}
for(rr int i=n;i>=1;--i){
if(i==n){
sss.push(mumumu[n]);
ans[i]=0;
}else{
while(mumumu[i].h>=sss.top().h){
sss.pop();
if(sss.empty()) break;
}
if(sss.empty()) ans[i]=0;
else ans[i]=sss.top().num;
sss.push(mumumu[i]);
}
}
for(rr int i=1;i<=n;++i){
printf("%d\n",ans[i]);
}
return 0;
}
洛谷 P2947 [USACO09MAR]向右看齐Look Up的更多相关文章
- 洛谷 P2947 [USACO09MAR]向右看齐Look Up【单调栈】
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...
- 洛谷P2947 [USACO09MAR]向右看齐Look Up
#include<cstdio> #include<algorithm> #include<stack> #include<cctype> using ...
- 洛谷P2947 [USACO09MAR]仰望Look Up
P2947 [USACO09MAR]仰望Look Up 74通过 122提交 题目提供者洛谷OnlineJudge 标签USACO2009云端 难度普及/提高- 时空限制1s / 128MB 提交 ...
- 【洛谷P2947】向右看齐
向右看齐 题目链接 此题可用单调栈O(n)求解 维护一个单调递减栈,元素从左到右入栈 若新加元素大于栈中元素,则栈中元素的仰望对象即为新加元素 每次将小于新加元素的栈中元素弹出,记录下答案 #incl ...
- 洛谷 P2947 [USACO09MAR]仰望Look Up
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...
- P2947 [USACO09MAR]向右看齐Look Up--单调栈
单调栈真的很好用呢! P2947 [USACO09MAR]向右看齐Look Up 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conven ...
- 【luogu P2947 [USACO09MAR]向右看齐Look Up】 题解
题目链接:https://www.luogu.org/problemnew/show/P2947 因为在单调队列上被dalao们锤爆 怒刷单调队列题 何为单调队列? 设我们的队列为从左至右单调递增 对 ...
- luogu P2947 [USACO09MAR]向右看齐Look Up |单调队列
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...
- 洛谷 P2945 [USACO09MAR]沙堡Sand Castle 题解
题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ...
随机推荐
- 深度剖析java中JDK动态代理机制
https://www.jb51.net/article/110342.htm 本篇文章主要介绍了深度剖析java中JDK动态代理机制 ,动态代理避免了开发人员编写各个繁锁的静态代理类,只需简单地指定 ...
- 计数数据存入Mysql
引用dll MySql.Data.dll 建一个数据连接静态类 public static class mysql{public static string constr = "databa ...
- 【JVM】记录一次线上SWAP偏高告警的故障分析过程
近期遇到一个堆外内存导致swap飙高的问题,这类问题比较罕见,因此将整个排查过程记录下来了 现象描述 最近1周线上服务器时不时出现swap报警(swap超过内存10%时触发报警,内存是4G,因此swa ...
- ORACLE ASMLIB
ORACLE ASMLIB This blog post is more of a note for myself on configuring ASMLib. ASMLib is an opti ...
- C#对MongDB取数据的常用代码
1.使用聚合取最新的实时数据(每一个测站有多条数据,取日期最新的数据.也就是每个测站取最新的值) var group = new BsonDocument { {"_id",new ...
- echarts Y轴名称显示不全(转载)
转载来源:https://blog.csdn.net/qq8241994/article/details/90720657今天在项目的开发中遇到的一个问题,echarts Y轴左侧的文字太多了,显示不 ...
- css display block 和 inline
根据CSS规范的规定,每一个网页元素都有一个display属性,用于确定该元素的类型,每一个元素都有默认的display属性值,比如div元素,它的默认display属性值为“block”,成为“块级 ...
- centos7 docker安装nginx
1.查询nginx最新镜像 docker search nginx 2.下载镜像 docker pull nginx 3.创建目录 mkdir -p /software/nginx/html mkdi ...
- 构建nodejs环境
总想留下点东西,不负年华! 00.download releasehttps://nodejs.org/dist/ //all release example https://nodejs. ...
- JWT对SpringCloud进行系统认证和服务鉴权
JWT对SpringCloud进行系统认证和服务鉴权 一.为什么要使用jwt?在微服务架构下的服务基本都是无状态的,传统的使用session的方式不再适用,如果使用的话需要做同步session机制,所 ...