思路:

单调栈。

鄙人的记忆:按当前为最大值的两边延伸就是维护单调递减栈。

//#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;
}

HDU 3410【单调栈】的更多相关文章

  1. hdu 3410 单调栈

    http://acm.hdu.edu.cn/showproblem.php?pid=3410 Passing the Message Time Limit: 2000/1000 MS (Java/Ot ...

  2. hdu 1506 单调栈问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目的意思其实就是要找到一个尽可能大的矩形来完全覆盖这个矩形下的所有柱子,只能覆盖柱子,不能留空 ...

  3. hdu 5033 单调栈 ****

    看出来是单调栈维护斜率,但是不会写,2333,原来是和询问放在一起的 #include <iostream> #include <cstdio> #include <cs ...

  4. hdu 5875(单调栈)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  5. HDU 5033 (单调栈维护凸包) Building

    题意: 一个人在x轴上,他的左右两侧都有高楼,给出楼的横坐标Xi和高度Hi还有人的位置pos,求人所能看到的天空的最大角度. 分析: 将建筑物和人的位置从左到右排序,对于每个位置利用栈求一次人左边建筑 ...

  6. hdu 4923 单调栈

    http://acm.hdu.edu.cn/showproblem.php?pid=4923 给定一个序列a,元素由0,1组成,求一个序列b,元素在0~1之间,并且保证递增.输出最小的∑(ai−bi) ...

  7. hdu 1505 单调栈升级版

    #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...

  8. hdu 1506 单调栈

    #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...

  9. hdu 3410 Passing the Message(单调队列)

    题目链接:hdu 3410 Passing the Message 题意: 说那么多,其实就是对于每个a[i],让你找他的从左边(右边)开始找a[j]<a[i]并且a[j]=max(a[j])( ...

随机推荐

  1. 我的Java开发学习之旅------>使用Working Setst将Eclipse中的项目分类使项目一目了然

    今天发现Eclipse中若有太多的项目,杂七杂八的,看起来会非常的痛苦.今天请教公司的前辈学会了一个方法,在Eclipse中,当项目比较多的时候,我们可以用WorkingSet将这些项目分类,把相关连 ...

  2. lambda map filter 用法

    lambda 可以这样认为,lambda作为一个表达式 非常容易理解,在这里lambda简化了函数定义的书写形式.是代码更为简洁,但是使用函数的定义方式更为直观,易理解. #定义函数:普通方式 def ...

  3. 查看物料凭证MB03 /MIGO A04-显示,R02-物料凭证

    当货物移动操作后,可以使用事物码MB03.MIGO查询最近一次生成的物料凭证, 如果未知凭证号,Table:MKPF / AUFM/EKBE MKPF 抬头:物料凭证 KEY: MBLNR 物料凭证编 ...

  4. Tomcat 开启远程调试

    根据 Tomcat 启动方式在 catalina.sh 或者 startup.sh 添加一下内容 $TOMCAT_HOME/bin/catalina.sh 添加 CATALINA_OPTS=" ...

  5. 《程序员代码面试指南》第八章 数组和矩阵问题 数组的partition 调整

    题目 数组的partition 调整 java代码 package com.lizhouwei.chapter8; /** * @Description: 数组的partition 调整 * @Aut ...

  6. png24 png8 jpeg与gif

    png24无损压缩,支持透明,有8位布尔透明通道,支持半透明,生成的图片品质最高,也最大 png8支持透明,有1位布尔透明通道,要么透明.要么半透明,生成的图片很小,只支持256色 jpeg有损压缩, ...

  7. win10系统使用clover时程序崩溃的解决

    1. 工具 --->  Internet选项 2. 程序选项卡 ---> 管理加载项 3.选择ExporerWatcher Class ---> 启用 win10对于未验证的程序状态 ...

  8. Zookeeper原理与Curator使用

    近期打算实现一个基于Zookeeper的分布式的集群状态一致性控制, 对Zookeeper的原理不太了解, 正好学习一下, 网上找到了几篇文章, 先贴在这边, 等我熟读官方文档后, 再来补充自己的见解 ...

  9. openfire插件(1)

    插件核心类,这里对PacketInterceptor.Plugin进行继承.如果开发插件就一定要继承Plugin,而继承PacketInterceptor是拦截用户发送的消息包.对消息包进行过滤.拦截 ...

  10. Dat.gui 使用教程

    官方站点:http://workshop.chromeexperiments.com/examples/gui/ Dat.gui 使用教程:Dat.gui 是一个 GUI 组件,他可以为你的 demo ...