当前位置:网站首页>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;
}
};
边栏推荐
- 51nod 1130 n factorial length V2 (Stirling approximation)
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- BOM - location, history, pop-up box, timing
- VPP performance test
- Viewing and verifying backup sets using dmrman
- [Key shake elimination] development of key shake elimination module based on FPGA
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- MySql数据库root账户无法远程登陆解决办法
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- 题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
猜你喜欢
DM8 backup set deletion
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
How many of the 10 most common examples of istio traffic management do you know?
One question per day (Mathematics)
Data processing methods - smote series and adasyn
[FPGA tutorial case 11] design and implementation of divider based on vivado core
【leetcode】1189. Maximum number of "balloons"
lora网关以太网传输
User datagram protocol UDP
[face recognition series] | realize automatic makeup
随机推荐
MySql数据库root账户无法远程登陆解决办法
Several important classes in unity
Fundamentals of SQL database operation
QML和QWidget混合开发(初探)
[disassembly] a visual air fryer. By the way, analyze the internal circuit
Path of class file generated by idea compiling JSP page
HotSpot VM
Basic knowledge of binary tree, BFC, DFS
Maxay paper latex template description
VPP performance test
One question per day (Mathematics)
DM8 archive log file manual switching
MySQL transaction isolation level
食品行业仓储条码管理系统解决方案
Database, relational database and NoSQL non relational database
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
Detailed explanation of serialization and deserialization
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
Lambda expression learning
Solution to the problem that the root account of MySQL database cannot be logged in remotely