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 分钟前
Cyber骇客的逻辑节点美学 ——【初阶数据结构与算法】二叉树
c语言·数据结构·c++·链表·排序算法
課代表17 分钟前
从初等数学到高等数学
算法·微积分·函数·极限·导数·积分·方程
ullio21 分钟前
arc206d - LIS ∩ LDS
算法
fpcc33 分钟前
C++编程实践—false_type和true_type的实践应用
c++
等等小何1 小时前
leetcode1593拆分字符串使唯一子字符串数目最大
算法
量子炒饭大师1 小时前
Cyber骇客神经塔尖协议 ——【初阶数据结构与算法】堆
c语言·数据结构·c++·二叉树·github·
王老师青少年编程2 小时前
2025年12月GESP(C++二级): 环保能量球
c++·算法·gesp·csp·信奥赛·二级·环保能量球
weixin_433417672 小时前
Canny边缘检测算法原理与实现
python·opencv·算法
CoderCodingNo2 小时前
【GESP】C++五级真题(贪心思想考点) luogu-P11960 [GESP202503 五级] 平均分配
开发语言·c++·算法
POLITE32 小时前
Leetcode 76.最小覆盖子串 JavaScript (Day 6)
javascript·算法·leetcode