![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
单调栈
goto_1600
我何来寂寞,哪有寂寞可言。
展开
-
AcWing 构造数组(单调栈)
构造数组 题意: 思路: 一开始想的枚举每一个山峰,然后往两边取min,然后TLE不知道怎么优化,正解是考虑单调栈,每一个l,r数组维护前缀、后缀的最大匹配值,例如l数组,对于a[i]而言,左边和它相邻所有比他大的数的贡献都是a[i]直到找到第一个比他小的数,那么就是a[i]*长度+l[stk[top]]; // Problem: 构造数组 // Contest: AcWing // URL: https://www.acwing.com/problem/content/description/3783/原创 2021-07-24 22:20:42 · 241 阅读 · 0 评论 -
思维+暴力(Function HDU - 5875 )
The shorter, the simpler. With this problem, you should be convinced of this truth. You are given an array A of N postive integers, and M queries in the form (l,r). A function F(l,r) (1≤l≤r≤N) is defi...原创 2020-04-17 21:26:23 · 245 阅读 · 0 评论 -
单调栈
题目 给定一个长度为N的整数数列,输出每个数左边第一个比它小的数,如果不存在则输出-1。 输入格式 第一行包含整数N,表示数列长度。 第二行包含N个整数,表示整数数列。 输出格式 共一行,包含N个整数,其中第i个数表示第i个数的左边第一个比它小的数,如果不存在则输出-1。 数据范围 1≤N≤1051≤N≤105 1≤数列中元素≤1091≤数列中元素≤109 输入样例: 5 3 4 2 7 5 输出...原创 2020-02-04 17:04:21 · 194 阅读 · 0 评论