// assume start < end // assume s <= start < end <= e void insert(int start, int end) { if (s == start && e == end) { inserted = true; return; } if (end <= p) { if (l == nullptr) l = new range(s, p); l->insert(start, end); } else if (start < p && end > p) { if (l == nullptr) l = new range(s, p); if (r == nullptr) r = new range(p, e); l->insert(start, p); r->insert(p, end); } else if (start >= p) { if (r == nullptr) r = new range(p, e); r->insert(start, end); } }
bool book(int start, int end) { if (r.conflict(start, end)) return false; r.insert(start, end); return true; }