Skip to content

Commit

Permalink
add links
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed Apr 9, 2023
1 parent efc89f3 commit 48e3ff0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
6 changes: 5 additions & 1 deletion copypasta/monotone_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ https://cp-algorithms.com/data_structures/stack_queue_modification.html
https://blog.csdn.net/weixin_43914593/article/details/105791217 算法竞赛专题解析(13):DP优化(3)--单调队列优化
todo https://xyzl.blog.luogu.org/DQ-OP-DP
模板题 https://leetcode.cn/problems/dui-lie-de-zui-da-zhi-lcof/
- [面试题 59-II. 队列的最大值](https://leetcode.cn/problems/dui-lie-de-zui-da-zhi-lcof/)(单调队列模板题)
- [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/)
- [862. 和至少为 K 的最短子数组](https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k/)
- [1438. 绝对差不超过限制的最长连续子数组](https://leetcode.cn/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/)
https://leetcode.cn/tag/monotonic-queue/problemset/
单调队列优化 DP
Expand Down
38 changes: 36 additions & 2 deletions copypasta/monotone_stack.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package copypasta

/* 单调栈 Monotone Stack
【图解单调栈】两种方法,两张图秒懂
https://leetcode.cn/problems/next-greater-node-in-linked-list/solution/tu-jie-dan-diao-zhan-liang-chong-fang-fa-v9ab/
举例:返回每个元素两侧严格大于它的元素位置(不存在则为 -1 或 n)
如何理解:把数组想象成一列山峰,站在 a[i] 的山顶仰望两侧的山峰,是看不到高山背后的矮山的,只能看到一座座更高的山峰
这就启发我们引入一个底大顶小的单调栈,入栈时不断比较栈顶元素直到找到一个比当前元素大的
Expand All @@ -12,11 +16,41 @@ package copypasta
https://oi-wiki.org/ds/monotonous-stack/
https://cp-algorithms.com/data_structures/stack_queue_modification.html
#### 单调栈
- [496. 下一个更大元素 I](https://leetcode.cn/problems/next-greater-element-i/)(单调栈模板题)
- [503. 下一个更大元素 II](https://leetcode.cn/problems/next-greater-element-ii/)
- [456. 132 模式](https://leetcode.cn/problems/132-pattern/)
- [739. 每日温度](https://leetcode.cn/problems/daily-temperatures/)
- [901. 股票价格跨度](https://leetcode.cn/problems/online-stock-span/)
- [1019. 链表中的下一个更大节点](https://leetcode.cn/problems/next-greater-node-in-linked-list/)
- [1124. 表现良好的最长时间段](https://leetcode.cn/problems/longest-well-performing-interval/)
- [1475. 商品折扣后的最终价格](https://leetcode.cn/problems/final-prices-with-a-special-discount-in-a-shop/)
- [2289. 使数组按非递减顺序排列](https://leetcode.cn/problems/steps-to-make-array-non-decreasing/)
#### 矩形系列
- [84. 柱状图中最大的矩形](https://leetcode.cn/problems/largest-rectangle-in-histogram/)
- [85. 最大矩形](https://leetcode.cn/problems/maximal-rectangle/)
- [1504. 统计全 1 子矩形](https://leetcode.cn/problems/count-submatrices-with-all-ones/)
#### 字典序最小
- [316. 去除重复字母](https://leetcode.cn/problems/remove-duplicate-letters/)
- [316 扩展:重复个数不超过 limit](https://leetcode.cn/contest/tianchi2022/problems/ev2bru/)
- [402. 移掉 K 位数字](https://leetcode.cn/problems/remove-k-digits/)
- [321. 拼接最大数](https://leetcode.cn/problems/create-maximum-number/)
#### 贡献法
- [907. 子数组的最小值之和](https://leetcode.cn/problems/sum-of-subarray-minimums/)
- [1856. 子数组最小乘积的最大值](https://leetcode.cn/problems/maximum-subarray-min-product/)
- [2104. 子数组范围和](https://leetcode.cn/problems/sum-of-subarray-ranges/)
- [2281. 巫师的总力量和](https://leetcode.cn/problems/sum-of-total-strength-of-wizards/)
模板题
https://www.luogu.com.cn/problem/P5788
https://www.luogu.com.cn/problem/P2866 http://poj.org/problem?id=3250
LC496 https://leetcode-cn.com/problems/next-greater-element-i/
LC503 https://leetcode-cn.com/problems/next-greater-element-ii/
NEERC05,UVa 1619 https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=825&page=show_problem&problem=4494
转换 https://codeforces.com/problemset/problem/280/B
Expand Down
1 change: 1 addition & 0 deletions copypasta/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sort.Ints 性能测试 https://codeforces.com/contest/977/submission/75301978
### 最小化最大值
- [2439. 最小化数组中的最大值](https://leetcode.cn/problems/minimize-maximum-of-array/)
- [2513. 最小化两个数组中的最大值](https://leetcode.cn/problems/minimize-the-maximum-of-two-arrays/)
- [2560. 打家劫舍 IV](https://leetcode.cn/problems/house-robber-iv/)
- [2616. 最小化数对的最大差值](https://leetcode.cn/problems/minimize-the-maximum-difference-of-pairs/)
### 最大化最小值
Expand Down
2 changes: 1 addition & 1 deletion leetcode/weekly/340/b/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

按照相同元素分组后再计算。

这里的思路和 [2602. 使数组元素全部相等的最少操作次数(题解)](https://leetcode.cn/problems/minimum-operations-to-make-all-array-elements-equal/solution/yi-tu-miao-dong-pai-xu-qian-zhui-he-er-f-nf55/) 是一样的。由于目标位置就是数组中的下标,无需二分。
这里的思路和 [2602. 使数组元素全部相等的最少操作次数(题解)](https://leetcode.cn/problems/minimum-operations-to-make-all-array-elements-equal/solution/yi-tu-miao-dong-pai-xu-qian-zhui-he-er-f-nf55/)是一样的。由于目标位置就是数组中的下标,无需二分。

```py [sol1-Python3]
class Solution:
Expand Down
2 changes: 1 addition & 1 deletion leetcode/weekly/340/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

二分数对中的最大差值 $mx$。

由于下标和答案无关,可以先排序。为了让差值最小,尽量选相邻的元素
由于下标和答案无关,可以先排序。为了让匹配的数对尽量多,应尽量选相邻的元素,这样更能满足要求

我们来算一算最多能匹配多少个数对:

Expand Down
2 changes: 1 addition & 1 deletion leetcode/weekly/340/d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $i$ 和 $j$ 均倒序遍历。答案为 $f[0][0]$。

但还有更「轻量级」的做法。

对于 $\min\limits_{k=j+1}^{j+g} f[i][k]$ 来说,在倒序遍历 $j$ 时,$k$ 的左边界 $j+1$ 是在**单调减小**的,我们可以用一个底大顶小的单调栈来维护 $f[i][k]$ 及其下标 $k$。由于是倒序遍历,单调栈中的下标也是底大顶小的,从那么在单调栈上二分查找最大的不超过 $j+g$ 的下标 $k$,对应的 $f[i][k]$ 就是 $[j+1, j+g]$ 范围内的最小值。
对于 $\min\limits_{k=j+1}^{j+g} f[i][k]$ 来说,在倒序遍历 $j$ 时,$k$ 的左边界 $j+1$ 是在**单调减小**的,我们可以用一个 $f$ 值底小顶大的单调栈来维护 $f[i][k]$ 及其下标 $k$。由于是倒序遍历,单调栈中的下标是底大顶小的,从那么在单调栈上二分查找最大的不超过 $j+g$ 的下标 $k$,对应的 $f[i][k]$ 就是 $[j+1, j+g]$ 范围内的最小值。

对于 $\min\limits_{k=i+1}^{i+g} f[k][j]$ 也同理,每一列都需要一个单调栈。

Expand Down

0 comments on commit 48e3ff0

Please sign in to comment.