voidaddRange(int left, int right){ int l = left; int r =right; auto p =mp.lower_bound(left);//找到第一个右端点大于left 的区间 while(p!=mp.end() && p->second<=r) { l = min(l,p->second); r = max(r,p->first); auto t =p; p++; mp.erase(t); } mp[r]=l; }
boolqueryRange(int left, int right){ auto p = mp.lower_bound(left); if(p==mp.end()) returnfalse; if(p->second<=left && p->first>= right) returntrue; returnfalse; }
voidremoveRange(int left, int right){ auto p = mp.lower_bound(left+1); while(p!=mp.end() && p->second<=right) { if(p->second<left) { mp[left] = p->second; } if(p->first>right) { mp[ p->first] =right; break; } else { auto t =p; p++; mp.erase(t); } } } };
/** * Your RangeModule object will be instantiated and called as such: * RangeModule* obj = new RangeModule(); * obj->addRange(left,right); * bool param_2 = obj->queryRange(left,right); * obj->removeRange(left,right); */