当前位置:网站首页>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;
}
};
边栏推荐
- Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
- 判断当天是当月的第几周
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- Hashcode and equals
- ESP32_ FreeRTOS_ Arduino_ 1_ Create task
- 绑定在游戏对象上的脚本的执行顺序
- 10個 Istio 流量管理 最常用的例子,你知道幾個?
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- 2/11 matrix fast power +dp+ bisection
- Simple blog system
猜你喜欢
Basic knowledge of binary tree, BFC, DFS
Stable Huawei micro certification, stable Huawei cloud database service practice
C mouse event and keyboard event of C (XXVIII)
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
[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
Practical development of member management applet 06 introduction to life cycle function and user-defined method
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Mysql数据库慢sql抓取与分析
Data processing methods - smote series and adasyn
随机推荐
【按键消抖】基于FPGA的按键消抖模块开发
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Ks003 mall system based on JSP and Servlet
20、 EEPROM memory (AT24C02) (similar to AD)
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
自动化测试的好处
Comprehensive ability evaluation system
Explain in simple terms node template parsing error escape is not a function
Determine which week of the month the day is
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Viewing and verifying backup sets using dmrman
How many of the 10 most common examples of istio traffic management do you know?
Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
Figure application details
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
pd. to_ numeric
Record the pit of NETCORE's memory surge
[001] [stm32] how to download STM32 original factory data
Hashcode and equals