当前位置:网站首页>2022.6.6-----leetcode. seven hundred and thirty-two
2022.6.6-----leetcode. seven hundred and thirty-two
2022-06-11 01:41:00 【Lu 727】
private Map<Integer, Integer> tree;// Line segment tree , Represents the value of a node
private Map<Integer, Integer> lazy;// Lazy mark
private int N;// Maximum range
public MyCalendarThree() {
tree = new HashMap<>();
lazy = new HashMap<>();
N= (int)1e9;
}
// Interval modification ( increase )
public void update(int l,int r,int val){
if(l>r) return;
update(l,r,1,N,1,val);
}
private void update( int l, int r,int curl, int curr, int node,int val) {
// Interval no intersection
if (curl>r||curr<l)
return;
// The current interval is within the target interval
if (l<=curl&&curr<=r) {
tree.put(node, tree.getOrDefault(node, 0) +val);// Update current node
if(curl<curr) lazy.put(node, lazy.getOrDefault(node, 0) + val);
} else {// There is an intersection between the current interval and the target interval
int mid = (curl + curr) >> 1;
if(lazy.getOrDefault(node,0)!=0)
pushDown(node);// Pass tag down
// Update the left and right child nodes
update( l, r, curl, mid,2 * node,val);
update(l, r, mid+1, curr, 2 * node + 1,val);
// Update current node
tree.put(node, Math.max(tree.getOrDefault(2 * node, 0),
tree.getOrDefault(2 * node + 1, 0)));
}
}
// Pass the tag to the next level
private void pushDown(int node){
int _lazy=lazy.getOrDefault(node,0);
lazy.put(node*2,lazy.getOrDefault(node*2,0)+_lazy);
lazy.put(node*2+1,lazy.getOrDefault(node*2+1,0)+_lazy);
tree.put(node*2,tree.getOrDefault(node*2,0)+_lazy);
tree.put(node*2+1,tree.getOrDefault(node*2+1,0)+_lazy);
lazy.put(node,0);
}
// Interval query
public int query(int l,int r){
if(l>r) return -1;
return query(l,r,1,N,1);
}
private int query(int l,int r,int curl,int curr,int node){
// Not in the target range
if(curl>r||curr<l)
return 0;
// In the target range
if(l<=curl&&curr<=r)
return tree.getOrDefault(node,0);
// Some have intersections , Split interval processing
int mid=(curl+curr)>>1;
if(lazy.getOrDefault(node,0)!=0)
pushDown(node);// Transmittal tag
return Math.max(query(l,r,curl,mid,node*2),query(l,r,mid+1,curr,node*2+1));
}
public int book(int start, int end) {
update(start,end-1,1);
return query(1,N);
}边栏推荐
- [chess life] 01 life is like chess
- Clean up the broken artifacts data (.lastUpdated files) and reload the project. Problem resolution
- 焱融看|混合云环境下,如何实现数据湖最优存储解决方案
- What is the C-end and what is the b-end? Let me tell you
- 1.6、 PX4初始化校准
- Introduction to the policy support of Beijing China Patent Award, with a subsidy of 1million yuan
- Multi interest recall model practice | acquisition technology
- 2.0、ROS与PX4通信详解
- How much is the bonus of China Patent Award, with a subsidy of 1million yuan
- CSRF attack
猜你喜欢

QGC ground station tutorial

1.5、PX4载具选择

Application of object storage S3 in distributed file system

From "0" to "tens of millions" concurrency, 14 technological innovations of Alibaba distributed architecture

QGC地面站使用教程

Multi interest recall model practice | acquisition technology

ROS参数服务器
![[path planning] week 1: hodgepodge](/img/80/074b847c6826b306318aeb9866a829.jpg)
[path planning] week 1: hodgepodge

detectron2训练自己的数据集和转coco格式

Sealem finance builds Web3 decentralized financial platform infrastructure
随机推荐
SAS主成分分析(求相关阵,特征值,单位特征向量,主成分表达式,贡献率和累计贡献率以及进行数据解释)
[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields
Yunna PDA wireless fixed assets inventory management system
SAS判别分析(Bayes准则和proc discrim过程)
Garbled code when the command parameter contains% in VisualStudio debugging
Introduction to the application process of China Patent Award, with a subsidy of 1million yuan
Introduction to the subsidy fund for leading technological innovation of Beijing enterprises, with a subsidy of 5million yuan
SAS聚类分析(系统聚类cluster,动态聚类fastclus,变量聚类varclus)
Beijing Yanqing District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
懒汉式单例模式
2.2、ROS+PX4仿真多点巡航飞行----正方形
2.1 ros+px4 simulation - Fixed Point flight control
Be careful, these hidden "bugs" of "array" to "collection"“
Some tips for programmers to deal with stress
Tencent cloud database tdsql- a big guy talks about the past, present and future of basic software
Once you know these treasure websites, you can't live without them!!!
中间件_Redis_06_Redis的事务
Introduction to the policy support of Shenzhen China Patent Award, with a subsidy of 1million yuan
SAS factor analysis (proc factor process, factor rotation and regression method for factor score function)
MultipartFile和File互转工具类