Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Index/分块.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
| 题目 | 题解 | 难度 | 推荐指数 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
| [933. 最近的请求次数](https://leetcode-cn.com/problems/number-of-recent-calls/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/number-of-recent-calls/solution/by-ac_oier-evqe/) | 简单 | 🤩🤩🤩🤩🤩 |
| [729. 我的日程安排表 I](https://leetcode.cn/problems/my-calendar-i/) | [LeetCode 题解链接](https://leetcode.cn/problems/my-calendar-i/solution/by-ac_oier-hnjl/) | 中等 | 🤩🤩🤩🤩 |
| [732. 我的日程安排表 III](https://leetcode-cn.com/problems/my-calendar-iii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/my-calendar-iii/solution/by-ac_oier-cv31/) | 困难 | 🤩🤩🤩 |
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |

2 changes: 2 additions & 0 deletions Index/单调队列.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| 题目 | 题解 | 难度 | 推荐指数 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
| [1438. 绝对差不超过限制的最长连续子数组](https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/solution/xiang-jie-er-fen-hua-dong-chuang-kou-dan-41g1/) | 中等 | 🤩🤩🤩 |
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |

2 changes: 2 additions & 0 deletions Index/堆.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
| [23. 合并K个升序链表](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/merge-k-sorted-lists/solution/shua-chuan-lc-you-xian-dui-lie-jie-fa-sh-3flb/) | 困难 | 🤩🤩🤩 |
| [218. 天际线问题](https://leetcode-cn.com/problems/the-skyline-problem/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/the-skyline-problem/solution/gong-shui-san-xie-sao-miao-xian-suan-fa-0z6xc/) | 困难 | 🤩🤩🤩 |
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
| [264. 丑数 II](https://leetcode-cn.com/problems/ugly-number-ii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/ugly-number-ii/solution/gong-shui-san-xie-yi-ti-shuang-jie-you-x-3nvs/) | 中等 | 🤩🤩🤩 |
| [295. 数据流的中位数](https://leetcode-cn.com/problems/find-median-from-data-stream/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/find-median-from-data-stream/solution/gong-shui-san-xie-jing-dian-shu-ju-jie-g-pqy8/) | 中等 | 🤩🤩🤩🤩 |
| [313. 超级丑数](https://leetcode-cn.com/problems/super-ugly-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/super-ugly-number/solution/gong-shui-san-xie-yi-ti-shuang-jie-you-x-jyow/) | 中等 | 🤩🤩🤩 |
Expand All @@ -26,5 +27,6 @@
| [1705. 吃苹果的最大数目](https://leetcode-cn.com/problems/maximum-number-of-eaten-apples/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-number-of-eaten-apples/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-hfdy0/) | 中等 | 🤩🤩🤩🤩🤩 |
| [1834. 单线程 CPU](https://leetcode-cn.com/problems/single-threaded-cpu/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/single-threaded-cpu/solution/gong-shui-san-xie-shu-ju-jie-gou-yun-yon-1qk0/) | 中等 | 🤩🤩🤩🤩 |
| [剑指 Offer 41. 数据流中的中位数](https://leetcode.cn/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/solution/by-ac_oier-exn5/) | 困难 | 🤩🤩🤩🤩🤩 |
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |
| [面试题 17.14. 最小K个数](https://leetcode-cn.com/problems/smallest-k-lcci/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/smallest-k-lcci/solution/gong-shui-san-xie-yi-ti-si-jie-you-xian-yy5k5/) | 中等 | 🤩🤩🤩🤩 |

2 changes: 2 additions & 0 deletions Index/线段树.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| 题目 | 题解 | 难度 | 推荐指数 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
| [307. 区域和检索 - 数组可修改](https://leetcode-cn.com/problems/range-sum-query-mutable/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/range-sum-query-mutable/solution/by-ac_oier-zmbn/) | 中等 | 🤩🤩🤩🤩🤩 |
| [327. 区间和的个数](https://leetcode.cn/problems/count-of-range-sum/) | [LeetCode 题解链接](https://leetcode.cn/problems/count-of-range-sum/solution/by-ac_oier-b36o/) | 困难 | 🤩🤩🤩🤩🤩 |
| [654. 最大二叉树](https://leetcode.cn/problems/maximum-binary-tree/) | [LeetCode 题解链接](https://leetcode.cn/problems/maximum-binary-tree/solution/by-ac_oier-s0wc/) | 中等 | 🤩🤩🤩🤩🤩 |
Expand All @@ -12,4 +13,5 @@
| [1109. 航班预订统计](https://leetcode-cn.com/problems/corporate-flight-bookings/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/corporate-flight-bookings/solution/gong-shui-san-xie-yi-ti-shuang-jie-chai-fm1ef/) | 中等 | 🤩🤩🤩🤩🤩 |
| [1893. 检查是否区域内所有整数都被覆盖](https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/solution/gong-shui-san-xie-yi-ti-shuang-jie-mo-ni-j83x/) | 简单 | 🤩🤩🤩🤩 |
| [2213. 由单个字符重复的最长子字符串](https://leetcode-cn.com/problems/longest-substring-of-one-repeating-character/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/longest-substring-of-one-repeating-character/solution/by-ac_oier-0lso/) | 困难 | 🤩🤩🤩🤩🤩 |
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |

2 changes: 1 addition & 1 deletion LeetCode/231-240/239. 滑动窗口最大值(困难).md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 题目描述

这是 LeetCode 上的 **[239. 滑动窗口最大值]()** ,难度为 **困难**。
这是 LeetCode 上的 **[239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/)** ,难度为 **困难**。

Tag : 「优先队列(堆)」、「线段树」、「分块」、「单调队列」、「RMQ」

Expand Down
10 changes: 5 additions & 5 deletions LeetCode/791-800/793. 阶乘函数后 K 个零(困难).md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ Tag : 「数学」、「二分」、「容斥原理」

### 数学 + 二分

对于一个 $n! = 1 \times 2 \times ... \times (n - 1) \times n$ 而言,其最终结果尾部包含 $0$ 的数量取决于其被累乘 $10$ 的次数,而 $10$ 可通过质因数 $2$ 和 $5$ 相乘而来,因此假设对 $n!$ 中的每一数进行阶乘分解,最终分解出 $2^p$ 和 $5^q$ 的话,那么最终结果尾部包含 $0$ 的个数为 $q$ 个(可证明 $p <= q$ 始终满足)。
对于一个 $n! = 1 \times 2 \times ... \times (n - 1) \times n$ 而言,其最终结果尾部包含 $0$ 的数量取决于其被累乘 $10$ 的次数,而 $10$ 可通过质因数 $2$ 和 $5$ 相乘而来,因此假设对 $n!$ 进行阶乘分解,最终分解出 $2^p$ 和 $5^q$ 的话,那么最终结果尾部包含 $0$ 的个数为 $q$ 个(可证明 $p >= q$ 始终满足)。

因此原问题转化为:在非负整数中,有多少个数进行阶乘分解后,所含质因数 $5$ 的个数为 $k$ 个。
因此原问题转化为:在非负整数中,有多少个数进行阶乘分解后,所含质因数 $5$ 的个数恰好为 $k$ 个。

同时我们可知:随着 $n$ 的增大,其所能分解出来的 $5$ 的个数必然是递增的。

基于此,我们可以通过「二分 + 容斥原理」来得出分解 $5$ 个数恰好为 $k$ 的连续段长度。假设我们存在函数 `f(k)` 可得到非负整数中分解 $5$ 个数为小于等于 `k` 的个数,那么最终 `f(k) - f(k - 1)` 即答案
基于此,我们可以通过「二分 + 容斥原理」来得出分解 $5$ 个数恰好为 $k$ 的连续段长度。假设我们存在函数 `f(k)` 可得到非负整数中分解 $5$ 个数为小于等于 `k` 的个数,那么最终 `f(k) - f(k - 1)` 即是答案

在单调函数上求解小于等于 `k` 分割点,可通过「二分」来做剩下的问题是,如何求得给定 `x` 时,其阶乘分解所包含 $5$ 个个数,这可以通过 $O(\log{x})$ 的筛法来做。
在单调函数上求解小于等于 `k` 分割点,可通过「二分」来做剩下的问题是,如何求得给定 `x` 时,其阶乘分解所包含 $5$ 个个数,这可以通过 $O(\log{x})$ 的筛法来做。

最后还要确定二分的值域,由于我们是求阶乘分解中 $5$ 的个数,因此值域的上界为 $5k$,利用 $k$ 的范围为 $1e9$,直接取成 $1e10$ 即可。

Expand Down Expand Up @@ -102,7 +102,7 @@ function getCnt(x: bigint): bigint {
return ans
}
```
* 时间复杂度:$O(\log{k})$
* 时间复杂度:$O(\log^2{k})$
* 空间复杂度:$O(1)$

---
Expand Down
Loading