class MyCalendarThree {
public:
MyCalendarThree() {
}
int book(int start, int end) {
}
};
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree* obj = new MyCalendarThree();
* int param_1 = obj->book(start,end);
*/
type pair struct{ num, lazy int }
type MyCalendarThree map[int]pair
func Constructor() MyCalendarThree {
return MyCalendarThree{}
}
func (t MyCalendarThree) update(start, end, l, r, idx int) {
if r < start || end < l {
return
}
if start <= l && r <= end {
p := t[idx]
p.num++
p.lazy++
t[idx] = p
} else {
mid := (l + r) / 2
t.update(start, end, l, mid, idx*2)
t.update(start, end, mid+1, r, idx*2+1)
p := t[idx]
p.num = p.lazy + max(t[idx*2].num, t[idx*2+1].num)
t[idx] = p
}
}
func (t MyCalendarThree) Book(start, end int) int {
t.update(start, end-1, 0, 1e9, 1)
return t[1].num
}
func max(a, b int) int {
if b > a {
return b
}
return a
}
/**
* Your MyCalendarThree object will be instantiated and called as such:
* obj := Constructor();
* param_1 := obj.Book(start,end);
*/