当前位置:网站首页>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);
*/
边栏推荐
- 代码规范 & 详细解释 husky、prettier、eslint、lint-staged 的作用和使用
- Solidworks渲染技巧如何不显示边线--显示样式设定
- Sqli labs range 1-5
- mysql性能監控和sql語句
- 18:第三章:开发通行证服务:1:短信登录&注册流程,简介;(这儿使用短信验证码)
- 【北邮果园微处理器设计】10 Serial Communication 串口通信笔记
- Fabric. JS upper dash, middle dash (strikethrough), underline
- Machine learning PCA - Experimental Report
- 动态规划解决股票问题(下)
- nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
猜你喜欢
10 years' experience in programmer career - for you who are confused
[Beiyou orchard microprocessor design] 10 serial communication serial communication notes
Excel operation of manual moving average method and exponential smoothing method for time series prediction
TCP interview
QT connection MySQL data query failed
LeetCode 710 黑名单中的随机数[随机数] HERODING的LeetCode之路
What does ack attack mean? How to defend against ack attacks?
How to calculate flops and params in deep learning
FastRCNN
Re recognized! Know that Chuangyu has been selected as one of the first member units of the "business security promotion plan"
随机推荐
loggie 编码以及换行符测试
ACK攻击是什么意思?ACK攻击怎么防御?
基于slate构建文档编辑器
Detailed explanation of MySQL fuzzy query
统计遗传学:第一章,基因组基础概念
基于slate构建文档编辑器
UDP flood attack defense principle
中国十大证券app排名 开户安全吗
FastRCNN
02 linked list of redis data structure
laravel 写原生SQL语句
Machine learning SVM - Experimental Report
(typora picture bed) Alibaba cloud OSS building picture bed +picgo uploading picture detailed tutorial
介紹一下實現建模中可能用到的時間序列預測之線性二次移動平均,Excel的簡單操作
laravel中使用group by分组并查询数量
3、 Linked list exercise
matlab 编程实例: 如何统计元胞数组中元素的数量
LeetCode 710 黑名单中的随机数[随机数] HERODING的LeetCode之路
I want to know whether flush is a stock market? Is it safe to open a mobile account?
Wangeditor uploading local video modification