当前位置:网站首页>leetcode 715. Range module (hard)
leetcode 715. Range module (hard)
2022-06-26 11:28: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);
*/
边栏推荐
- Work report (3)
- flannel的host-gw与calico
- TCP interview
- Cet article présente la moyenne mobile quadratique linéaire et le fonctionnement simple d'Excel pour réaliser la prédiction des séries chronologiques dans la modélisation.
- TCP面试
- 18: Chapter 3: development of pass service: 1: SMS login & registration process, introduction; (SMS verification code is used here)
- [deep learning theory] (6) recurrent neural network RNN
- Splicing full paths and uploading multiple pictures of laravel admin when laravel uses OSS
- 在Oracle中update大量数据会不会导致undo空间爆掉
- Laravel-admin 登录添加图形验证码
猜你喜欢

Nacos2.x.x start error creating bean with name 'grpcclusterserver';

ctfshow web入门 命令执行web75-77
![[deep learning theory] (7) long and short term memory network LSTM](/img/fb/57781998390e0722df68e6c2e49098.gif)
[deep learning theory] (7) long and short term memory network LSTM

深度理解STM32的串口实验(寄存器)【保姆级教程】

That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade

Implementing MySQL master-slave replication in docker

02-Redis数据结构之链表

(Typora图床)阿里云oss搭建图床+Picgo上传图片详细教程

Code specification & explain in detail the functions and uses of husky, prettier, eslint and lint staged

【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
随机推荐
即构「畅直播」上线!提供全链路升级的一站式直播服务
Easyx-----c语言实现2048
UDP flood attack defense principle
Laravel-admin 登录添加图形验证码
18: Chapter 3: development of pass service: 1: SMS login & registration process, introduction; (SMS verification code is used here)
介紹一下實現建模中可能用到的時間序列預測之線性二次移動平均,Excel的簡單操作
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
matlab 编程实例: 如何统计元胞数组中元素的数量
【深度学习理论】(6) 循环神经网络 RNN
PC qq Hall upload Update Modifying versioninfo
What does ack attack mean? How to defend against ack attacks?
深度理解STM32的串口實驗(寄存器)【保姆級教程】
Work report (3)
SolidWorks rendering tips how not to display edges -- display style settings
nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
我想知道同花顺是炒股的么?手机开户安全么?
滑动窗口
MOS管基本原理,单片机重要知识点
PC QQ大厅 上传更新 修改versionInfo
Machine learning LDA - Experimental Report