当前位置:网站首页>729. My schedule I (set or dynamic open point segment tree)
729. My schedule I (set or dynamic open point segment tree)
2022-07-06 04:16:00 【Harris-H】
729. My schedule I(set or Dynamic open point line segment tree )
Interval coverage , Interval query . Therefore, the value range is large , Small number of queries , So open it dynamically .
The tree building method is similar to the ordinary segment tree , Namely pushdown It is decided whether the left and right sons are empty , Then all functions can use pointers .
Time complexity : O ( n l o g C ) O(nlogC) O(nlogC)
class MyCalendar {
public:
struct node{
node *l,*r;
int s,lz;
};
node * rt = new node();
const int NN = 1e9;
MyCalendar() {
}
void re(node* a){
a->s=a->l->s|a->r->s;
}
void pd(node* a){
if(a->l==NULL) a->l= new node();
if(a->r==NULL) a->r= new node();
if(!a->lz) return;
a->l->s=a->lz;
a->r->s=a->lz;
a->l->lz=a->r->lz=a->lz;
a->lz=0;
}
void upd(node *a,int l,int r,int L,int R,int v){
if(l>=L&&r<=R){
a->s=v;
a->lz=v;return;
}
pd(a);
int m = l+r>>1;
if(L<=m) upd(a->l,l,m,L,R,v);
if(R>m) upd(a->r,m+1,r,L,R,v);
re(a);
}
bool que(node *a,int l,int r,int L,int R){
if(l>=L&&r<=R) return a->s;
int m = l+r>>1;
pd(a);
int ok=0;
if(L<=m) ok|=que(a->l,l,m,L,R);
if(R>m) ok|=que(a->r,m+1,r,L,R);
return ok;
}
bool book(int st, int ed) {
if(que(rt,0,NN,st,ed-1)) return false;
upd(rt,0,NN,st,ed-1,1);
return true;
}
};
set, Practice every time lower_bound l>=ed Of Location p p p.
And then determine ( − − p ) → r ≤ s t < e d ≤ l (--p)\rightarrow r\le st<ed\le l (−−p)→r≤st<ed≤l
Time complexity : O ( n l o g n ) O(nlogn) O(nlogn)
class MyCalendar {
set<pair<int, int>> booked;
public:
bool book(int start, int end) {
auto it = booked.lower_bound({
end, 0});
if (it == booked.begin() || (--it)->second <= start) {
booked.emplace(start, end);
return true;
}
return false;
}
};
边栏推荐
- How to execute an SQL statement in MySQL
- In depth MySQL transactions, stored procedures and triggers
- 10个 Istio 流量管理 最常用的例子,你知道几个?
- JVM garbage collector concept
- 电脑钉钉怎么调整声音
- MySQL master-slave replication
- 1008 circular right shift of array elements (20 points)
- P2648 make money
- 《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
猜你喜欢

Security xxE vulnerability recurrence (XXe Lab)

10 exemples les plus courants de gestion du trafic istio, que savez - vous?

How many of the 10 most common examples of istio traffic management do you know?
![[Key shake elimination] development of key shake elimination module based on FPGA](/img/47/c3833c077ad89d4906e425ced945bb.png)
[Key shake elimination] development of key shake elimination module based on FPGA

Comprehensive ability evaluation system

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server

About some basic DP -- those things about coins (the basic introduction of DP)

Lombok principle and the pit of ⽤ @data and @builder at the same time

Benefits of automated testing

Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
随机推荐
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
CertBot 更新证书失败解决
颠覆你的认知?get和post请求的本质
About some basic DP -- those things about coins (the basic introduction of DP)
2/13 review Backpack + monotonic queue variant
hashlimit速率控制
. Net interprocess communication
Fundamentals of SQL database operation
729. 我的日程安排表 I(set or 动态开点线段树)
Lombok原理和同时使⽤@Data和@Builder 的坑
Path of class file generated by idea compiling JSP page
1291_ Add timestamp function in xshell log
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Solve the compilation problem of "c2001: line breaks in constants"
Fedora/rehl installation semanage
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
Cross domain and jsonp details