主席樹動態

2021-09-13 14:38:48 字數 1405 閱讀 7924

以zoj2114為模板題。

主席樹的動態單點改值主要是主席樹加樹狀陣列,具體暫未理解,待熟練仔細揣摩。

**如下

#include

#include

#include

#include

#include

using

namespace std;

const

int maxn =

60000

;struct nood q[maxn +5]

;int a[maxn +5]

, t[

2* maxn +5]

;int root[maxn *32+

5], l[maxn *32+

5], r[maxn *32+

5], cnt[maxn *32+

5];int s[maxn +5]

, ul[maxn +5]

, ur[maxn +5]

;int n, m, q, tot;

void

build

(int

&rt,

int l,

int r)

void

insert

(int

&rt,

int pre,

int l,

int r,

int x,

int val)

intlowbit

(int x)

void

add(

int x,

int val)

}int

sum(

int x,

bool kind)

return res;

}int

query

(int posl,

int posr,

int nodel,

int noder,

int l,

int r,

int k)

else

}void

init()

else

}sort

(t +

1, t + m +1)

; m =

unique

(t +

1, t + m +1)

- t -1;

}int

main()

for(

int i =

1; i <= q; i++

)else}}

return0;

}

posted @

2018-10-15 17:56

呵呵!!! 閱讀(

...)

編輯收藏

動態主席樹

zoj 2112 include include include include define ll long long using namespace std const int maxn 10000 15 16 陣列註解 root 代表主席樹的每個數字對應點的節點編號 a 原陣列的數 hash ...

主席樹 動態 模板

自己整理模板,僅作模板儲存使用 include using namespace std const int maxn 6e4 5 主席樹最多需要在原空間上開大40倍,原空間本身首先要加大,這題原空間為50000 const int maxm 1e4 5 int t maxn s maxn l max...

主席樹 動態 Kth

1 zoj2112 2動態 kth 3每一棵線段樹是維護每乙個序列字首的值在任意區間的個數,4如果還是按照靜態的來做的話,那麼每一次修改都要遍歷o n 棵樹,5時間就是o 2 m nlogn tle 6考慮到字首和,我們通過樹狀陣列來優化,即樹狀陣列套主席樹,7每個節點都對應一棵主席樹,那麼修改操作...