Skip to content

Commit ef8d500

Browse files
authored
Merge pull request #690 from LetMeFly666/732
添加问题“732.我的日程安排表III”的代码和题解
2 parents 2c046c3 + c02d539 commit ef8d500

9 files changed

+424
-2
lines changed

Codes/0732-my-calendar-iii.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-01-05 21:26:02
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-01-05 21:33:46
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class MyCalendarThree {
12+
private:
13+
unordered_map<int, int> tree, lazy;
14+
15+
void update(int start, int end, int index, int l, int r) {
16+
if (start > r || l > end) {
17+
return;
18+
}
19+
if (l >= start && r <= end) {
20+
tree[index]++;
21+
lazy[index]++;
22+
} else {
23+
int mid = (l + r) >> 1;
24+
update(start, end, index * 2 + 1, l, mid);
25+
update(start, end, index * 2 + 2, mid + 1, r);
26+
tree[index] = lazy[index] + max(tree[index * 2 + 1], tree[index * 2 + 2]);
27+
}
28+
}
29+
public:
30+
MyCalendarThree() {}
31+
32+
int book(int startTime, int endTime) {
33+
update(startTime, endTime - 1, 0, 0, 1000000000);
34+
return tree[0];
35+
}
36+
};
37+
38+
/**
39+
* Your MyCalendarThree object will be instantiated and called as such:
40+
* MyCalendarThree* obj = new MyCalendarThree();
41+
* int param_1 = obj->book(startTime,endTime);
42+
*/

Codes/0732-my-calendar-iii.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-01-05 21:45:30
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-01-05 21:57:58
6+
*/
7+
package main
8+
9+
type pair_myCalendarIII struct {num, lazy int}
10+
type MyCalendarThree map[int]pair_myCalendarIII
11+
12+
func max_MC3(a, b int) int {
13+
if a > b {
14+
return a
15+
}
16+
return b
17+
}
18+
19+
func Constructor() MyCalendarThree {
20+
return MyCalendarThree{}
21+
}
22+
23+
func (this MyCalendarThree) update(start, end, index, l, r int) {
24+
if l > end || start > r {
25+
return
26+
}
27+
if l >= start && r <= end {
28+
p := this[index]
29+
p.num++ // 不可直接this[index].num++
30+
p.lazy++
31+
this[index] = p
32+
} else {
33+
mid := (l + r) >> 1
34+
this.update(start, end, index * 2 + 1, l, mid)
35+
this.update(start, end, index * 2 + 2, mid + 1, r)
36+
p := this[index]
37+
p.num = this[index].lazy + max_MC3(this[index * 2 + 1].num, this[index * 2 + 2].num)
38+
this[index] = p
39+
}
40+
}
41+
42+
func (this MyCalendarThree) Book(startTime int, endTime int) int {
43+
this.update(startTime, endTime - 1, 0, 0, 1000000000)
44+
return this[0].num
45+
}
46+
47+
48+
/**
49+
* Your MyCalendarThree object will be instantiated and called as such:
50+
* obj := Constructor();
51+
* param_1 := obj.Book(startTime,endTime);
52+
*/

Codes/0732-my-calendar-iii.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-01-05 21:39:30
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-01-05 21:44:12
6+
*/
7+
import java.util.HashMap;
8+
9+
class MyCalendarThree {
10+
private HashMap<Integer, Integer> tree, lazy;
11+
12+
private void update(int start, int end, int index, int l, int r) {
13+
if (l > end || start > r) {
14+
return;
15+
}
16+
if (l >= start && r <= end) {
17+
tree.put(index, tree.getOrDefault(index, 0) + 1);
18+
lazy.put(index, lazy.getOrDefault(index, 0) + 1);
19+
} else {
20+
int mid = (l + r) >> 1;
21+
update(start, end, index * 2 + 1, l, mid);
22+
update(start, end, index * 2 + 2, mid + 1, r);
23+
tree.put(index, lazy.getOrDefault(index, 0) + Math.max(tree.getOrDefault(index * 2 + 1, 0), tree.getOrDefault(index * 2 + 2, 0)));
24+
}
25+
}
26+
27+
public MyCalendarThree() {
28+
tree = new HashMap<Integer, Integer>();
29+
lazy = new HashMap<Integer, Integer>();
30+
}
31+
32+
public int book(int startTime, int endTime) {
33+
update(startTime, endTime - 1, 0, 0, 1000000000);
34+
return tree.get(0);
35+
}
36+
}
37+
38+
/**
39+
* Your MyCalendarThree object will be instantiated and called as such:
40+
* MyCalendarThree obj = new MyCalendarThree();
41+
* int param_1 = obj.book(startTime,endTime);
42+
*/

Codes/0732-my-calendar-iii.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-01-05 21:34:19
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-01-05 21:38:20
6+
'''
7+
from collections import defaultdict
8+
9+
class MyCalendarThree:
10+
11+
def __init__(self):
12+
self.tree = defaultdict(int)
13+
self.lazy = defaultdict(int)
14+
15+
def update(self, start: int, end: int, index: int, l: int, r: int) -> None:
16+
if l > end or start > r:
17+
return
18+
if start <= l and r <= end:
19+
self.tree[index] += 1
20+
self.lazy[index] += 1
21+
else:
22+
mid = (l + r) >> 1
23+
self.update(start, end, index * 2 + 1, l, mid)
24+
self.update(start, end, index * 2 + 2, mid + 1, r)
25+
self.tree[index] = self.lazy[index] + max(self.tree[index * 2 + 1], self.tree[index * 2 + 2])
26+
27+
def book(self, startTime: int, endTime: int) -> int:
28+
self.update(startTime, endTime - 1, 0, 0, 1000000000)
29+
return self.tree[0]
30+
31+
32+
# Your MyCalendarThree object will be instantiated and called as such:
33+
# obj = MyCalendarThree()
34+
# param_1 = obj.book(startTime,endTime)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
|0724.寻找数组的中心下标|简单|<a href="https://leetcode.cn/problems/find-pivot-index/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/08/LeetCode%200724.%E5%AF%BB%E6%89%BE%E6%95%B0%E7%BB%84%E7%9A%84%E4%B8%AD%E5%BF%83%E4%B8%8B%E6%A0%87/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140266165" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-pivot-index/solutions/2835007/letmefly-724xun-zhao-shu-zu-de-zhong-xin-36y4/" target="_blank">LeetCode题解</a>|
255255
|0729.我的日程安排表I|中等|<a href="https://leetcode.cn/problems/my-calendar-i/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/02/LeetCode%200729.%E6%88%91%E7%9A%84%E6%97%A5%E7%A8%8B%E5%AE%89%E6%8E%92%E8%A1%A8I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144889921" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/my-calendar-i/solutions/3036765/letmefly-729wo-de-ri-cheng-an-pai-biao-i-5yzd/" target="_blank">LeetCode题解</a>|
256256
|0731.我的日程安排表II|中等|<a href="https://leetcode.cn/problems/my-calendar-ii/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/03/LeetCode%200731.%E6%88%91%E7%9A%84%E6%97%A5%E7%A8%8B%E5%AE%89%E6%8E%92%E8%A1%A8II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144908626" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/my-calendar-ii/solutions/3037464/letmefly-731wo-de-ri-cheng-an-pai-biao-i-o7lm/" target="_blank">LeetCode题解</a>|
257+
|0732.我的日程安排表III|困难|<a href="https://leetcode.cn/problems/my-calendar-iii/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/05/LeetCode%200732.%E6%88%91%E7%9A%84%E6%97%A5%E7%A8%8B%E5%AE%89%E6%8E%92%E8%A1%A8III/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144951803" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/my-calendar-iii/solutions/3039527/letmefly-732wo-de-ri-cheng-an-pai-biao-i-gwea/" target="_blank">LeetCode题解</a>|
257258
|0735.行星碰撞|中等|<a href="https://leetcode.cn/problems/asteroid-collision/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/13/LeetCode%200735.%E8%A1%8C%E6%98%9F%E7%A2%B0%E6%92%9E/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125774687" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/asteroid-collision/solution/by-tisfy-nxaa/" target="_blank">LeetCode题解</a>|
258259
|0746.使用最小花费爬楼梯|简单|<a href="https://leetcode.cn/problems/min-cost-climbing-stairs/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/17/LeetCode%200746.%E4%BD%BF%E7%94%A8%E6%9C%80%E5%B0%8F%E8%8A%B1%E8%B4%B9%E7%88%AC%E6%A5%BC%E6%A2%AF/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135046961" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/min-cost-climbing-stairs/solutions/2569770/letmefly-746shi-yong-zui-xiao-hua-fei-pa-pz2r/" target="_blank">LeetCode题解</a>|
259260
|0749.隔离病毒|困难|<a href="https://leetcode.cn/problems/contain-virus/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/18/LeetCode%200749.%E9%9A%94%E7%A6%BB%E7%97%85%E6%AF%92/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125846470" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/contain-virus/solution/letmefly-749ge-chi-bing-du-by-tisfy-746u/" target="_blank">LeetCode题解</a>|

Solutions/LeetCode 0406.根据身高重建队列.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 406.根据身高重建队列
33
date: 2022-10-17 10:24:51
4-
tags: [题解, LeetCode, 中等, 贪心, 树状数组, 线段树, 数组, 排序]
4+
tags: [题解, LeetCode, 中等, 贪心, 树状数组, 数组, 排序]
55
---
66

77
# 【LetMeFly】406.根据身高重建队列

0 commit comments

Comments
 (0)