第 442 场周赛-20250323
https://leetcode.cn/contest/weekly-contest-442
中国时间:2025-03-23 10:30, 1 小时 30 分
3492.船上可以装载的最大集装箱数量
https://leetcode.cn/problems/maximum-containers-on-a-ship/
3493.属性图
graph, bfs, https://leetcode.cn/problems/properties-graph/
3494.酿造药水需要的最少总时间
implementation, https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions/
3495.使数组元素变为零的最少操作次数
https://leetcode.cn/problems/minimum-operations-to-make-array-elements-zero/
给你一个二维数组 queries,其中 queries[i] 形式为 [l, r]。每个 queries[i] 表示了一个元素范围从 l 到 r (包括 l 和 r )的整数数组 nums 。
在一次操作中,你可以:
- 选择一个查询数组中的两个整数
a和b。 - 将它们替换为
floor(a / 4)和floor(b / 4)。
你的任务是确定对于每个查询,将数组中的所有元素都变为零的 最少 操作次数。返回所有查询结果的总和。
示例 1:
输入: queries = [[1,2],[2,4]]
输出: 3
解释:
对于 queries[0]:
- 初始数组为
nums = [1, 2]。 - 在第一次操作中,选择
nums[0]和nums[1]。数组变为[0, 0]。 - 所需的最小操作次数为 1。
对于 queries[1]:
- 初始数组为
nums = [2, 3, 4]。 - 在第一次操作中,选择
nums[0]和nums[2]。数组变为[0, 3, 1]。 - 在第二次操作中,选择
nums[1]和nums[2]。数组变为[0, 0, 0]。 - 所需的最小操作次数为 2。
输出为 1 + 2 = 3。
示例 2:
输入: queries = [[2,6]]
输出: 4
解释:
对于 queries[0]:
- 初始数组为
nums = [2, 3, 4, 5, 6]。 - 在第一次操作中,选择
nums[0]和nums[3]。数组变为[0, 3, 4, 1, 6]。 - 在第二次操作中,选择
nums[2]和nums[4]。数组变为[0, 3, 1, 1, 1]。 - 在第三次操作中,选择
nums[1]和nums[2]。数组变为[0, 0, 0, 1, 1]。 - 在第四次操作中,选择
nums[3]和nums[4]。数组变为[0, 0, 0, 0, 0]。 - 所需的最小操作次数为 4。
输出为 4。
提示:
1 <= queries.length <= 10^5queries[i].length == 2queries[i] == [l, r]1 <= l < r <= 10^9
python