HDU 3410【单调栈】
来源:互联网 发布:怎么做网络平台 编辑:程序博客网 时间:2024/05/22 02:07
思路:
单调栈。
鄙人的记忆:按当前为最大值的两边延伸就是维护单调递减栈。
单调栈。
鄙人的记忆:按当前为最大值的两边延伸就是维护单调递减栈。
//#include <bits/stdc++.h>#include <iostream>#include <stack>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <vector>#include <map>using namespace std;typedef long long LL;typedef pair<int,int> PII;const int N=50000+10;struct asd{ int id; int left,right,w;};int n,a[N];int ans[N][2];stack<asd>q;int main(){ while(!q.empty()) q.pop(); int T,cas=1; scanf("%d",&T); while(T--) { asd now,nex; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); now.id=1; now.left=now.right=1; now.w=a[1]; q.push(now); for(int i=2;i<=n;i++) { nex.id=i; nex.left=nex.right=i; nex.w=a[i]; while(!q.empty()&&q.top().w<a[i]) { now=q.top();q.pop(); ans[now.id][0]=now.left!=now.id?now.left:0; ans[now.id][1]=now.right!=now.id?now.right:0; if(!q.empty()) q.top().right=now.id; nex.left=now.id; } q.push(nex); } while(!q.empty()) { now=q.top();q.pop(); ans[now.id][0]=now.left!=now.id?now.left:0; ans[now.id][1]=now.right!=now.id?now.right:0; if(!q.empty()) q.top().right=now.id; } printf("Case %d:\n",cas++); for(int i=1;i<=n;i++) printf("%d %d\n",ans[i][0],ans[i][1]); } return 0;}
0 0
- hdu 3410 单调栈
- HDU 3410【单调栈】
- HDU 3410 Passing the Message (单调栈)
- hdu 3410(单调队列)
- hdu~3410(单调队列)
- hdu 3855 单调栈
- hdu 4923 单调栈
- HDU 4252(单调栈)
- HDU 1506 单调栈
- hdu 4252(单调栈)
- HDU 5033 单调栈
- HDU 1506【单调栈】
- hdu 5033(单调栈)
- hdu 3410(单调队列)
- HDU 5033 Building (单调栈)
- 【HDU】5033 Building 单调栈
- HDU 5033 Building (单调栈)
- hdu 5033 Building 单调栈
- python基础语法——循环(二)
- 【树莓派】添加rtl8192eu无线网卡驱动
- elasticsearch中的字段类型/mapping参数
- 系统级性能分析工具 — Perf
- C语言-输入任意多个数字,数字间用空格隔开,然后将数字求和。
- HDU 3410【单调栈】
- Thinkphp3.2监控sql报警或超时
- centos7下lamp快速搭建环境
- qt 问题
- HDU 1506【单调栈】
- tomcat session管理
- Spring事务管理(基础概念)
- 控制Dialog的窗口大小(自定义Dialog视图)
- Oracle数据库sql--单表查询