当前位置:网站首页>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;
}
};
边栏推荐
- Record the pit of NETCORE's memory surge
- 【leetcode】22. bracket-generating
- Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
- 10个 Istio 流量管理 最常用的例子,你知道几个?
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- Brief tutorial for soft exam system architecture designer | general catalog
- Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- lora网关以太网传输
- TCP/IP协议里面的网关地址和ip地址有什么区别?
猜你喜欢

Proof of Stirling formula

Ipv4中的A 、B、C类网络及子网掩码

Simple blog system

MySql數據庫root賬戶無法遠程登陸解决辦法

DM8 archive log file manual switching

《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动

Thread sleep, thread sleep application scenarios

Viewing and verifying backup sets using dmrman

Record the pit of NETCORE's memory surge

Interface idempotency
随机推荐
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
In depth MySQL transactions, stored procedures and triggers
About some basic DP -- those things about coins (the basic introduction of DP)
Thread sleep, thread sleep application scenarios
Security xxE vulnerability recurrence (XXe Lab)
Stack and queue
Record the pit of NETCORE's memory surge
Ipv4中的A 、B、C类网络及子网掩码
How does technology have the ability to solve problems perfectly
颠覆你的认知?get和post请求的本质
Mathematical modeling regression analysis relationship between variables
Several important classes in unity
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
Database, relational database and NoSQL non relational database
HotSpot VM
Solution to the problem that the root account of MySQL database cannot be logged in remotely
About some basic DP -- those things about coins (the basic introduction of DP)
[001] [stm32] how to download STM32 original factory data
Use js to complete an LRU cache
Script lifecycle