#include
using
namespace std;
const
int maxn=
1e5+5;
int dat[maxn<<2]
,cov[maxn<<2]
;int a[maxn]
;void
inline
pushup
(int p)
void
build
(int p,
int l,
int r)
int mid=l+r>>1;
build
(p<<
1,l,mid)
;build
(p<<1|
1,mid+
1,r)
;pushup
(p);
}void
pushdown
(int p,
int l,
int r)
}void
change
(int p,
int l,
int r,
int x,
int y)
pushdown
(p,l,r)
;int mid=l+r>>1;
if(x<=mid)
change
(p<<
1,l,mid,x,y)
;else
change
(p<<1|
1,mid+
1,r,x,y)
;pushup
(p);
}void
change
(int p,
int l,
int r,
int ql,
int qr,
int x)
pushdown
(p,l,r)
;int mid=l+r>>1;
if(ql<=mid)
change
(p<<
1,l,mid,ql,qr,x);if
(qr>mid)
change
(p<<1|
1,mid+
1,r,ql,qr,x)
;pushup
(p);
}int
ask(
int p,
int l,
int r,
int x)
intask
(int p,
int l,
int r,
int ql,
int qr)
intmain()
else
}return0;
}
注意點:
對一顆樹的子樹進行修改時,必須先pushdown
如果不pushdown這顆樹,反而對它的乙個子樹進行修改,那麼pushup時會出現錯誤
query的時候也需要pushdown,如果一顆樹的lazy值不為零,而又query該樹的子樹,也會出現錯誤
線段樹模板(模板)
參考部落格 持續更新。外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳 img xhrgdjcd 1613976863463 區間儲存在陣列中的下標對應為 12 3 4 5 6 7 8 9 10 11 12 13 14 15 四部分單點更新 根據題目的要求編寫自己的pushup,query...
線段樹模板
include include include using namespace std const int size 10010 struct node the node of line tree class linetree void updatem void updateline public ...
線段樹模板
單點更新,區間求最值 include include include include include define n 222222 using namespace std int num n struct tree tree n 4 void push up int root void build...