http://acm.hdu.edu.cn/showproblem.php?pid=3410

初探单调栈,从左往右,求l,从右往左,求r。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std; int a[],l[],r[],n;
stack<int> s; int main()
{
int T;
scanf("%d",&T);
for(int z = ;z <= T;z++)
{
while(!s.empty()) s.pop();
printf("Case %d:\n",z);
scanf("%d",&n);
for(int i = ;i <= n;i++) scanf("%d",&a[i]);
for(int i = ;i <= n;i++)
{
int temp = -;
while(!s.empty() && a[s.top()] < a[i])
{
temp = s.top();
s.pop();
}
l[i] = temp == -?:temp;
s.push(i);
}
while(!s.empty()) s.pop();
for(int i = n;i >= ;i--)
{
int temp = -;
while(!s.empty() && a[s.top()] < a[i])
{
temp = s.top();
s.pop();
}
r[i] = temp == -?:temp;
s.push(i);
}
for(int i = ;i <= n;i++) printf("%d %d\n",l[i],r[i]);
}
return ;
}

HDU_3410_单调栈的更多相关文章

  1. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  2. BZOJ 4453: cys就是要拿英魂![后缀数组 ST表 单调栈类似物]

    4453: cys就是要拿英魂! Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 90  Solved: 46[Submit][Status][Discu ...

  3. BZOJ 3238: [Ahoi2013]差异 [后缀数组 单调栈]

    3238: [Ahoi2013]差异 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2326  Solved: 1054[Submit][Status ...

  4. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

  5. bzoj1510: [POI2006]Kra-The Disks(单调栈)

    这道题可以O(n)解决,用二分还更慢一点 维护一个单调栈,模拟掉盘子的过程就行了 #include<stdio.h> #include<string.h> #include&l ...

  6. BZOJ1057[ZJOI2007]棋盘制作 [单调栈]

    题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方阵,对应八八六十四卦,黑白对应阴阳. 而我们的 ...

  7. 洛谷U4859matrix[单调栈]

    题目描述 给一个元素均为正整数的矩阵,上升矩阵的定义为矩阵中每行.每列都是严格递增的. 求给定矩阵中上升子矩阵的数量. 输入输出格式 输入格式: 第一行两个正整数n.m,表示矩阵的行数.列数. 接下来 ...

  8. POJ3250[USACO2006Nov]Bad Hair Day[单调栈]

    Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17774   Accepted: 6000 Des ...

  9. CodeForces 548D 单调栈

    Mike and Feet Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. Mixing Milk 混合牛奶 USACO 贪心

    1009: 1.3.1 Mixing Milk 混合牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1. ...

  2. Linux删除文件 清除缓存

    相信很多测试 经常会经历开发叫你清除缓存这种事. 那我们要怎么清呢? 一.首先,确认你要清除的缓存在哪个目录下,然后切换到该目录下,比如 我现在知道我的的缓存目录是在newerp这个目录下,则如图 二 ...

  3. 【Magicodes.IE 2.0.0-beta1版本发布】已支持数据表格、列筛选器和Sheet拆分

    为了更好的完善Magicodes.IE,春节期间我们会进行一次大的重构.由于精力有限,急缺文档和翻译(将文档翻译为英文文档)支持,诚邀各位加入.同时在功能方便也做了相关规划,有兴趣的朋友可以参与提交P ...

  4. FWT 入门

    #include <bits/stdc++.h> using namespace std; #define ll long long const ll maxn = 3e5+5; cons ...

  5. NETCore下IConfiguration和IOptions的用法

    NETCore下IConfiguration和IOptions的用法 https://www.cnblogs.com/RainingNight/p/strongly-typed-options-con ...

  6. 保存数据到csv

    csv 逗号分隔值 一.写入 1.列表 单行添加 import csv # with open(file='a.csv', mode='w', encoding='utf-8', newline='' ...

  7. 10.JavaSE之包机制

    包机制: 为了更好的组织类,Java提供了包机制,用于区别类名的命名空间 包语句的语法格式为: package pkg1[ . pkg2[ . pkg3...]]; package com.duan. ...

  8. A complex 16-Level XSS Challenge

    A complex 16-Level XSS Challenge, held in summer 2014 (+1 Hidden Level) Index Level 0 Level 1 Level ...

  9. python 获取一个网页里的a 标签

    #!/usr/bin/python # -*- coding: utf-8 -*- #encoding=utf-8 #Filename:urllib2-header.py import re impo ...

  10. 用自定义变量作为动作方法参数 URL路由 精通ASP-NET-MVC-5-弗瑞曼