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;
}
相关推荐
hold?fish:palm12 小时前
20 旋转图像
c++·算法·leetcode
此生决int13 小时前
深入理解C++系列(10)——lsit
开发语言·c++
NoteStream13 小时前
【C语言基础】分支和循环(上)
c语言·开发语言·c++·经验分享·笔记·算法·c#
2401_8274999913 小时前
C++(黑马)05-提高编程
java·开发语言·c++
白狐_79813 小时前
408数据结构第7章:查找②——顺序、折半、分块查找秒杀 + 真题
数据结构·算法
卷心菜的学习路13 小时前
基于多模态向量检索的数学相似题推荐系统:完整设计、算法与实验
java·python·算法·大模型·推荐算法·数学相似题
小南知更鸟13 小时前
【leetcodehot100】leetcode-hot100-20260809更新
算法·leetcode·职场和发展
数模竞赛Paid answer13 小时前
2021年深圳杯数学建模A题火星探测器着陆控制方案解题全过程论文及程序
算法·数学建模·深圳杯
hold?fish:palm14 小时前
19 螺旋矩阵
线性代数·算法·矩阵
hold?fish:palm14 小时前
链表的基本原理和实现(C++版本)
数据结构·c++·链表