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;
}
相关推荐
朔北之忘 Clancy7 小时前
2025 CSP-J 第二轮真题解析
c++·青少年编程·题解·noip·csp·信奥赛·noi
longlongzihan7 小时前
LeetCode 17电话号码的字母组合:回溯算法(DFS)详解
c++·算法·leetcode·深度优先
yolo_guo7 小时前
调试mysql延迟与libevent回调实际发送回复时机问题
c++·mysql·libevent
封印师请假去地球钓鱼7 小时前
边解边变的问题:从“决策依赖“一词出发
人工智能·算法
今晚打老虎8 小时前
c++之提高A(前缀和)(第三课)
数据结构·c++·算法
不会就选b9 小时前
算法日常・每日刷题--<贪心>26
数据结构·算法
by209999 小时前
从结构体到对象:正式学习C++类的骨架、封装与this指针
c++·经验分享·学习
2601_9622186110 小时前
C语言中三种库的编译和使用方法
开发语言·c++
jimy110 小时前
派生类重写基类虚函数(二):override的作用
开发语言·c++
ebiobiz10 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu