当前位置:网站首页>2022.6.20-----leetcode. seven hundred and fifteen
2022.6.20-----leetcode. seven hundred and fifteen
2022-06-26 03: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;
public RangeModule() {
tree = new HashMap<Integer, Integer>();
lazy = new HashMap<Integer, Integer>();
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) {
int sum=tree.getOrDefault(node, 0);// Current interval and
if(val==1&&sum<(curr-curl+1)*val){// Some nodes in the current interval are not tracked
tree.put(node,(curr-curl+1)*val);// Update current node
if(curl<curr) lazy.put(node, 1);
}else if(val==-1&&sum>0) {// There are tracked nodes in the current interval
tree.put(node, 0);// Update current node
if (curl < curr) lazy.put(node, -1);
}
} 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,curr-curl+1);
update( l, r, curl, mid,2 * node,val);
update(l, r, mid+1, curr, 2 * node + 1,val);
tree.put(node, tree.getOrDefault(2 * node, 0)+tree.getOrDefault(2 * node + 1, 0));
}
}
// Pass the tag to the next level
private void pushDown(int node,int len){
int _lazy=lazy.get(node);
int sum1=tree.getOrDefault(node*2,0);
int sum2=tree.getOrDefault(node*2+1,0);
if(_lazy==1){
// Untracked nodes exist in the interval
if(sum1<(len-len/2)*_lazy){
lazy.put(node*2,1);
tree.put(node*2,(len-len/2)*_lazy);
}
if(sum2<len/2*_lazy){
lazy.put(node*2+1,1);
tree.put(node*2+1,len/2*_lazy);
}
}else{
// There are tracked nodes in the interval
if(sum1>0){
lazy.put(node*2,-1);
tree.put(node*2,0);
}
if(sum2>0){
lazy.put(node*2+1,-1);
tree.put(node*2+1,0);
}
}
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,curr-curl+1);
return query(l,r,curl,mid,node*2)+query(l,r,mid+1,curr,node*2+1);
}
public void addRange(int left, int right) {
update( left, right - 1, 1);
}
public boolean queryRange(int left, int right) {
return query(left, right - 1) == right - left;
}
public void removeRange(int left, int right) {
update(left, right - 1, -1);
}边栏推荐
- “再谈”协议
- Analysis on the diversification of maker space mechanism construction
- 优化——多目标规划
- How Inkscape converts PNG pictures to SVG pictures without distortion
- Tupu software is the digital twin of offshore wind power, striving to be the first
- Request object, send request
- Andorid hide the title bar of the system
- Group counting notes - instruction pipeline of CPU
- 经典模型——NiN&GoogLeNet
- Hardware creation principle of campus maker space
猜你喜欢
![[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters](/img/84/2b66b513a0a36464233708fbb4b57d.png)
[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters
![[hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long](/img/82/6a81e5b0d5117d780ce5910698585a.jpg)
[hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long

解决uniapp插件robin-editor设置字体颜色和背景颜色报错的问题

Google recommends using kotlin flow in MVVM architecture

The "eye" of industrial robot -- machine vision

Run multiple main functions in the clion project
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct

显卡、GPU、CPU、CUDA、显存、RTX/GTX及查看方式

类图

Add an "open search description" to the site to adapt to the browser's "site search"“
随机推荐
Andorid hide the title bar of the system
How Inkscape converts PNG pictures to SVG pictures without distortion
【Appium踩坑】io.appium.uiautomator2.common.exceptions.InvalidArgumentException: ‘capabilities‘ are mand
MySQL高级篇第一章(linux下安装MySQL)【下】
关于#sql#的问题:SQL问题--账号多地登录的SQL代码
Double carbon bonus + great year of infrastructure construction 𞓜 deep ploughing into the field of green intelligent equipment for water conservancy and hydropower
评价——层次分析
Qixia fire department carries out fire safety training on construction site
项目部署遇到的问题-生产环境
MySQL开发环境
Hardware creation principle of campus maker space
拖放
Problems encountered in project deployment - production environment
经典模型——AlexNet
Various errors in kitti2bag installation
Insect structure and Deconstruction
Kotlin learning apply plugin: 'kotlin Android extensions‘
Worm copy construction operator overload
Kotlin quick start
Classic model alexnet