当前位置:网站首页>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);
*/
边栏推荐
- 深度学习中的FLOPs和Params如何计算
- Qixia housing and Urban Rural Development Bureau and fire rescue brigade carried out fire safety training
- Group by is used in laravel to group and query the quantity
- 量化初级 -- akshare获得股票代码,最简策略
- QT connection MySQL data query failed
- HUST网络攻防实践|6_物联网设备固件安全实验|实验三 FreeRTOS-MPU 保护绕过
- 杜比全景音效简介
- Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
- PC QQ大厅 上传更新 修改versionInfo
- laravel-admin 非自增ID获取, 及提交隐藏表单
猜你喜欢

(typora picture bed) Alibaba cloud OSS building picture bed +picgo uploading picture detailed tutorial

.net中,日志组件 Nlog,SerialLog, Log4Net的用法

SolidWorks rendering tips how not to display edges -- display style settings

Excel operation of manual moving average method and exponential smoothing method for time series prediction

TCP面试

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

Svn installation configuration
![In depth understanding of STM32 serial port experiment (register) [nanny level tutorial]](/img/b2/f09e220918a85b14a1993aa85f7720.png)
In depth understanding of STM32 serial port experiment (register) [nanny level tutorial]

Easyx-----c语言实现2048

Fabric. JS upper dash, middle dash (strikethrough), underline
随机推荐
Redis的最佳实践?看完不心动,算我输!!
Svn installation configuration
wangEditor 上传本地视频修改
FastRCNN
基于slate构建文档编辑器
代码规范 & 详细解释 husky、prettier、eslint、lint-staged 的作用和使用
HUST网络攻防实践|6_物联网设备固件安全实验|实验二 基于 MPU 的物联网设备攻击缓解技术
Recent work report
9、 Beautify tables, forms, and hyperlinks
ctfshow web入门 命令执行web75-77
Will updating a large amount of data in Oracle cause the undo space to explode
Compréhension approfondie de l'expérience de port série stm32 (registre) [Tutoriel de niveau nounou]
Laravel admin hidden button, and set button display, default sequence, form form form non modifiable value
express在nodejs中的基本使用
Machine learning PCA - Experimental Report
Black squares in word
Machine learning linear regression - Experimental Report
02-Redis数据结构之链表
Using baijiafan to automatically generate API calls: progress in JS (II)
介绍一下实现建模中可能用到的时间序列预测之线性二次移动平均,Excel的简单操作