POJ3250 Bad Hair Day(单调栈)
2016-03-01 21:14
357 查看
题目大概就是给一个序列,问每个数右边有几个连续且小于该数的数。
用单调递减栈搞搞就是了。
用单调递减栈搞搞就是了。
#include<cstdio> #include<cstring> using namespace std; #define INF (1<<30) #define MAXN 88888 int a[MAXN],r[MAXN],stack[MAXN],top; int main(){ int n; scanf("%d",&n); for(int i=1; i<=n; ++i) scanf("%d",a+i); a[++n]=INF; for(int i=1; i<=n; ++i){ while(top && a[stack[top]]<=a[i]){ r[stack[top]]=i-1; --top; } stack[++top]=i; } long long res=0; for(int i=1; i<n; ++i) res+=r[i]-i; printf("%lld",res); return 0; }
相关文章推荐
- 玩转AI(Adobe illustrator)——小西瓜(2)
- Codeforces AIM Tech Round (Div. 2)
- 玩转AI(Adobe illustrator)——小西瓜(1)
- UtalPTR 运行报错 Didn't find class "in.srain.cube.image.CubeImageView" on path: DexPathList[[zip file
- 设计模式入门之职责链模式Chain Of Responsibility
- openchain 环境部署
- linux系统调用之-fork、wait、waitpid
- Lock wait timeout exceeded; try restarting transaction
- MICCAI 2015 partI 论文简单总结
- POJ - 3691 DNA repair
- Codeforces 627B Factory Repairs 【线段树】
- leetcode 每日一题 70. Climbing Stairs
- 【ZOJ3921 2016年浙大2月月赛I】【物理题 底乘高积分式思维】In the Rain 圆柱体人行走 吸收雨体积
- AIO
- nonatomic, retain,weak,strong用法详解
- Provisioning Profile -- 运行报错 Command /usr/bin/codesign failed with exit code 1
- mongodb启动不了:child process failed, exited with error number 100
- UVa 10245 The Closest Pair Problem 分治
- AIDL学习笔记
- SharePoint2010 Error:Failed to call GetTypes on assembly Microsoft.Office.InfoPath.Server解决方案