当前位置:网站首页>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;
}
};
边栏推荐
- HotSpot VM
- Lora gateway Ethernet transmission
- pd. to_ numeric
- Execution order of scripts bound to game objects
- C mouse event and keyboard event of C (XXVIII)
- In depth MySQL transactions, stored procedures and triggers
- MySQL about self growth
- P2648 make money
- 【leetcode】1189. Maximum number of "balloons"
- Class A, B, C networks and subnet masks in IPv4
猜你喜欢

In depth MySQL transactions, stored procedures and triggers

Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts

MySQL master-slave replication

How does technology have the ability to solve problems perfectly
![[disassembly] a visual air fryer. By the way, analyze the internal circuit](/img/73/29553d60f47deadfff420be40b7f77.jpg)
[disassembly] a visual air fryer. By the way, analyze the internal circuit

Data processing methods - smote series and adasyn

Stable Huawei micro certification, stable Huawei cloud database service practice

Record an excel xxE vulnerability

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

Security xxE vulnerability recurrence (XXe Lab)
随机推荐
P2648 make money
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
Hashcode and equals
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Stack and queue
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
MySql数据库root账户无法远程登陆解决办法
MySQL about self growth
Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
Solution to the problem that the root account of MySQL database cannot be logged in remotely
IDEA编译JSP页面生成的class文件路径
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
Brief tutorial for soft exam system architecture designer | general catalog