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;
}
相关推荐
浅念-2 小时前
Linux 开发环境与工具链
linux·运维·服务器·数据结构·c++·经验分享
旺仔.2912 小时前
容器适配器:stack栈 、queue队列、priority queue优先级队列、bitset位图 详解
c++
刘景贤3 小时前
C/C++开发环境
开发语言·c++
Zero5 小时前
机器学习微积分--(1)核心思想
人工智能·算法·机器学习
OasisPioneer5 小时前
现代 C++ 全栈教程 - Modern-CPP-Full-Stack-Tutorial
开发语言·c++·开源·github
有Li5 小时前
一种病理学内容感知变速率学习图像压缩框架 (PathoLIC)/文献速递-多模态应用技术
人工智能·深度学习·算法·计算机视觉·医学生
liulilittle5 小时前
XDP to TC : TUN eBPF NAT
c++
x_xbx5 小时前
LeetCode:34. 在排序数组中查找元素的第一个和最后一个位置
数据结构·算法·leetcode
花开莫与流年错_5 小时前
ZeroMQ基本示例使用
c++·消息队列·mq·示例·zeromq
Ricky_Theseus5 小时前
数据库关系代数 - 连接操作
linux·数据库·算法