Re: [閒聊] 每日LeetCode

看板Marginalman作者 (愛麗絲)時間1年前 (2022/10/07 19:36), 編輯推噓1(103)
留言4則, 3人參與, 1年前最新討論串35/719 (看更多)
732. My Calendar III 我好不容易用線段樹刻完了 結果只比5%的快,哭了 class MyCalendarThree { public: static const int maxEd = 1000000000; unordered_map<uint64_t,int> maxB; unordered_map<uint64_t,int> add; MyCalendarThree() {} int insert(int st, int ed, int l = 0, int r = maxEd) { uint64_t key = ((uint64_t)l << 32) | r; if (st <= l && r <= ed) { add[key] += 1; return maxB[key] + add[key]; } int m = (l + r) / 2; if (st <= m) maxB[key] = max(maxB[key], insert(st, ed, l , m)); if (ed >= m + 1) maxB[key] = max(maxB[key], insert(st, ed, m + 1, r)); return maxB[key] + add[key]; } int book(int st, int ed) { return insert(st, ed - 1); } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.16.175 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1665142577.A.DFC.html

10/07 19:38, 1年前 , 1F
寶 你可以用陣列來刻 對ㄚ
10/07 19:38, 1F

10/07 19:38, 1年前 , 2F
大師
10/07 19:38, 2F

10/07 19:43, 1年前 , 3F
用陣列比較難做吧 總不能開個2*10^9的陣列
10/07 19:43, 3F

10/07 19:55, 1年前 , 4F
ㄛ 我沒看測資 那你用自己的NODE來做會比較好吧
10/07 19:55, 4F
文章代碼(AID): #1ZG0ynty (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ZG0ynty (Marginalman)