当前位置:网站首页>729. 我的日程安排表 I(set or 动态开点线段树)
729. 我的日程安排表 I(set or 动态开点线段树)
2022-07-06 04:11:00 【Harris-H】
729. 我的日程安排表 I(set or 动态开点线段树)
区间覆盖,区间查询。因此值域大,查询次数小,所以动态开点。
建树方法与普通线段树类似,就是pushdown的时候特判下左右儿子是否位空,然后所有函数都用指针即可。
时间复杂度: 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,做法每次就lower_bound l>=ed的 位置 p p p。
然后判断 ( − − p ) → r ≤ s t < e d ≤ l (--p)\rightarrow r\le st<ed\le l (−−p)→r≤st<ed≤l
时间复杂度: 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;
}
};
边栏推荐
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- Lombok原理和同时使⽤@Data和@Builder 的坑
- Chinese brand hybrid technology: there is no best technical route, only better products
- math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
- 【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
- C (XXIX) C listbox CheckedListBox Imagelist
- Cross domain and jsonp details
- 10个 Istio 流量管理 最常用的例子,你知道几个?
- Custom event of C (31)
- Recommendation system (IX) PNN model (product based neural networks)
猜你喜欢
20、 EEPROM memory (AT24C02) (similar to AD)
MySql数据库root账户无法远程登陆解决办法
Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Overturn your cognition? The nature of get and post requests
Interface idempotency
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
No qualifying bean of type ‘......‘ available
自动化测试的好处
Figure application details
随机推荐
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
Ks003 mall system based on JSP and Servlet
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
食品行业仓储条码管理系统解决方案
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
Detailed explanation of serialization and deserialization
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
DM8 archive log file manual switching
Lambda expression learning
MySql数据库root账户无法远程登陆解决办法
How does technology have the ability to solve problems perfectly
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
脚本生命周期
WPF effect Article 191 box selection listbox
10个 Istio 流量管理 最常用的例子,你知道几个?
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
No qualifying bean of type ‘......‘ available
[Key shake elimination] development of key shake elimination module based on FPGA