線段樹模板

2021-07-29 21:05:34 字數 1004 閱讀 2697

博主為了ctrl+c方便,沒事寫了這篇文章(以後持續更新)

現在包括的操作有:單點修改(單點加)、區間求和、區間加(修改)、線段樹二分

#include#include#include#include#include#include#includeusing namespace std;

#define ll long long

const int n=1000010;

const int max=1e9+7;

int n,k;

int a[n],len;

inline void r(int &v)

while(isdigit(ch))

if(f) v=-v;

}namespace ib

inline void p(int x)

if(x<0)

char *s=ib::b;

while(x) *(++s)=x%10, x/=10;

while(s!=ib::b) putchar((*(s--))+48);

}struct segtree

tree[n<<2];

void updata(int o)//更新

void build(int o,int l,int r)//建樹

int mid=(l+r)>>1;

build(o<<1,l,mid);

build(o<<1|1,mid+1,r);

updata(o); }

void release(int o)//更新懶標記

void modify(int o,int ql,int qr,int v)//區間加

updata(o); }

int query(int o,int ql,int qr)//區間和

updata(o);

return res;

}

線段樹模板(模板)

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