当前位置:网站首页>leetcode 715. Range 模块 (hard)
leetcode 715. Range 模块 (hard)
2022-06-26 10:41:00 【king9666】


class RangeModule {
private:
map<int,int> mp;
public:
RangeModule() {
}
void addRange(int left, int right) {
int l = left, r = right;
auto p = mp.lower_bound(left);
while(p != mp.end() && p -> second <= right)
{
l = min(l,p->second);
r = max(r,p->first);
auto temp = p;
p++;
mp.erase(temp->first);
}
mp[r] = l;
}
bool queryRange(int left, int right) {
auto p = mp.lower_bound(left);
if(p == mp.end())
return false;
if(p -> second <= left && p -> first >= right)
return true;
return false;
}
void removeRange(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 temp = p;
p++;
mp.erase(temp->first);
}
}
}
};
/**
* 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);
*/
边栏推荐
- JWT certification agreement -- I opened a Yihong hospital
- 基于slate构建文档编辑器
- dd命令测试华为鲲鹏&宏衫固态存储磁盘读写速度
- 即构「畅直播」上线!提供全链路升级的一站式直播服务
- Group by is used in laravel to group and query the quantity
- (Typora图床)阿里云oss搭建图床+Picgo上传图片详细教程
- QT connection MySQL data query failed
- MySQL模糊查询详解
- (typora picture bed) Alibaba cloud OSS building picture bed +picgo uploading picture detailed tutorial
- 一键部署ceph脚本
猜你喜欢
随机推荐
Please advise tonghuashun which securities firm to choose for opening an account? Is it safe to open a mobile account?
请指教同花顺开户选选择哪家券商比较好?手机开户安全么?
哈希表的前置知识---二叉搜索树
redux相关用法
Group by is used in laravel to group and query the quantity
Apiccloud implements the document download and preview functions
MySQL Performance Monitoring and SQL statements
nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
MySQL模糊查询详解
Pre knowledge of hash table -- binary search tree
What does ack attack mean? How to defend against ack attacks?
MQTT断开重连
Flannel's host GW and calico
Recent work report
openresty 概述
深度理解STM32的串口实验(寄存器)【保姆级教程】
PC QQ大廳 上傳更新 修改versionInfo
Origin of b+ tree index
基于slate构建文档编辑器
在Oracle中update大量数据会不会导致undo空间爆掉









