Untitled
unknown
plain_text
14 days ago
873 B
2
Indexable
Never
// segment tree class MyCalendarThree { public: MyCalendarThree() { } unordered_map<int, int> seg, lazy; void update(int id, int s, int e, int tl, int tr){ // out of range if(e < tl || tr < s) return; if(s <= tl && tr <= e){ lazy[id]++; seg[id]++; } else{ int mid = (tl + tr) / 2; update(2*id, s, e, tl, mid); update(2*id + 1, s, e, mid+1, tr); seg[id] = lazy[id] + max(seg[2*id], seg[2*id + 1]); } } int book(int s, int e) { update(1, s, e-1, 0, 1e9); return seg[1]; } }; /** * Your MyCalendarThree object will be instantiated and called as such: * MyCalendarThree* obj = new MyCalendarThree(); * int param_1 = obj->book(startTime,endTime); */
Leave a Comment