線段樹模板

2022-08-22 21:48:09 字數 2067 閱讀 1720

1

struct

node

2 st[4*maxn+5];6

long

long

a[maxn];7//

修改求和還是維護區間最小值

8long

long operation(long

long a,long

longb)9

13//

修改求和還是維護區間最小值

14void change(int pos,long

long addmark,int

l)15

1

void build(int root,int ibegin,int

iend)

213 }

1

void push_down(int root,intl)2

1

long

long query(int root,int ibegin,int iend,int qbegin,int

qend)

2

1

void updata(int root,int ibegin,int iend,int qbegin,int qend,long

long

addmark)

211 push_down(root,iend-ibegin+1

);12

int mid = (ibegin+iend)/2

;13 updata(root*2

,ibegin,mid,qbegin,qend,addmark);

14 updata(root*2+1,mid+1

,iend,qbegin,qend,addmark);

15 st[root].val = operation(st[root*2].val,st[root*2+1

].val);

16 }

總:

1

const

int maxn = 100004;2

struct

node

3 st[4*maxn+5];7

long

long

a[maxn];8//

修改求和還是維護區間最小值

9long

long operation(long

long a,long

long

b)10

14//

修改求和還是維護區間最小值

15void change(int pos,long

long addmark,int

l)16

19void build(int root,int ibegin,int

iend)

2031}32

void push_down(int root,int

l)33

42long

long query(int root,int ibegin,int iend,int qbegin,int

qend)

4352

void updata(int root,int ibegin,int iend,int qbegin,int qend,long

long

addmark)

5362 push_down(root,iend-ibegin+1

);63

int mid = (ibegin+iend)/2

;64 updata(root*2

,ibegin,mid,qbegin,qend,addmark);

65 updata(root*2+1,mid+1

,iend,qbegin,qend,addmark);

66 st[root].val = operation(st[root*2].val,st[root*2+1

].val);

67 }

匯流排段樹

線段樹模板(模板)

參考部落格 持續更新。外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳 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...