Acwing 830. 单调栈

Acwing 830. 单调栈

题目描述

代码展示

cpp 复制代码
#include <iostream>

using namespace std;

const int N = 100010;

int stk[N], tt;

int main()
{
    int n;
    cin >> n;
    while (n -- )
    {
        int x;
        scanf("%d", &x);
        while (tt && stk[tt] >= x) tt -- ;
        if (!tt) printf("-1 ");
        else printf("%d ", stk[tt]);
        stk[ ++ tt] = x;
    }

    return 0;
}
相关推荐
放羊郎8 小时前
基于ORB-SLAM2算法的优化工作
人工智能·算法·计算机视觉
mask哥8 小时前
力扣算法java实现汇总整理(上)
java·算法·leetcode
如果'\'真能转义说9 小时前
OOXML 文档格式剖析:哈希、ZIP结构与识别
xml·算法·c#·哈希算法
王老师青少年编程10 小时前
csp信奥赛C++高频考点专项训练之字符串 --【子串查找】:[NOIP 2009 提高组] 潜伏者
c++·字符串·csp·高频考点·信奥赛·子串查找·潜伏者
梦梦代码精10 小时前
BuildingAI 上部署自定义工作流智能体:5 个实用技巧
大数据·人工智能·算法·开源软件
初願致夕霞10 小时前
基于系统调用的Linux网络编程——UDP与TCP
linux·网络·c++·tcp/ip·udp
Zephyr_011 小时前
Leedcode算法题
java·算法
流年如夢11 小时前
栈和列队(LeetCode)
数据结构·算法·leetcode·链表·职场和发展
小小de风呀12 小时前
de风——【从零开始学C++】(五):内存管理
开发语言·c++