【BZOJ】3401: [Usaco2009 Mar]Look Up 仰望(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=3401
还能更裸一些吗。。
维护一个递减的单调栈
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1e5+100;
int n, h[N], top, q[N], d[N]; void work() {
for1(i, 1, n) {
while(top && h[q[top]]<h[i]) d[q[top--]]=i;
q[++top]=i;
}
} int main() {
read(n);
for1(i, 1, n) read(h[i]);
work();
for1(i, 1, n) printf("%d\n", d[i]);
return 0;
}
Description
Input
Output
Sample Input
3
2
6
1
1
2
Sample Output
3
0
6
6
0
HINT
Source
【BZOJ】3401: [Usaco2009 Mar]Look Up 仰望(单调栈)的更多相关文章
- BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )
n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...
- bzoj 3401: [Usaco2009 Mar]Look Up 仰望【单调栈】
用单调递减的栈从后往前扫一遍即可 #include<iostream> #include<cstdio> using namespace std; const int N=10 ...
- BZOJ 3401: [Usaco2009 Mar]Look Up 仰望(离线+平衡树)
刷银组刷得好开心= = 离线按权值排序,从大到小插入二叉树,查找树中比这个数大的 CODE: #include<cstdio>#include<iostream>#includ ...
- 3401: [Usaco2009 Mar]Look Up 仰望
3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 136 Solved: 81[Submi ...
- BZOJ3401: [Usaco2009 Mar]Look Up 仰望
3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 87 Solved: 58[Submit ...
- DP经典 BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生
BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 419 Solve ...
- bzoj 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...
- BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...
- bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害
1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着 ...
随机推荐
- profile_oracle设置某用户password永只是期
原创作品.出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46888139 or ...
- LoadRunner+Android模所器实现抓包并调试本地服务端
步骤就是 1:新建LR脚本.协议选择Mobile Application - HTTP/HTML 2:在record里选择第三个:Record Emulator........ 3: 选择下一步后, ...
- Apache Drupal URL重写【转】
文章来源:http://www.cnblogs.com/ghj1976/archive/2010/07/19/1780844.html 在 drupal 跟目录下有个 .htaccess 文件, 这个 ...
- vpngate 的使用
第一次为小日本打广告.. .我仅仅想仰天大喊..玛的戈壁. .. 竟然活到这个份上了...想出去看看的往下看.. vpngate 下载: http://pan.baidu.com/s/1hq5x3Ly ...
- CSS3中伪类nth-child和nth-of-type区别
本篇文章由:http://xinpure.com/css3-pseudo-class-difference-between-nthchild-and-nthoftype/ 首先来看看 nth-chil ...
- SQL数据表插入随机数(转)
declare @T TABLE (id int identity(1,1),[Name] nvarchar(20), Randnum int) insert @T ([Name]) select ' ...
- web开发中常见的安全漏洞及避免方法
1.安全攻击 1.SQL.HTML.JS.OS命令注入 2.XSS跨站脚本攻击,利用站内信任的用户,在web页面插入恶意script代码 3.CSRF跨站请求伪造,通过伪装来自信任用户的请求来利用受信 ...
- 基于DDD的.NET开发框架-DDD经典分层
DDD核心思想是由业务问题来控制解决方案的形式从以数据库为中心过渡到领域模型为中心 下面这个图是我在<领域驱动设计与模式实战>书中拍下来的,他完全诠释DDD的经典分层. 程序代码中也是响应 ...
- 【Android】Architecture Components最佳实践--Lifecycles
UI controllers (activities and fragments) 中代码越少越好,不应该自己去请求数据,而是用ViewModel来更新数据,并且监听LiveData来更新UI UI ...
- Lintcode---单词的添加与查找
设计一个包含下面两个操作的数据结构:addWord(word), search(word) addWord(word)会在数据结构中添加一个单词.而search(word)则支持普通的单词查询或是只包 ...