1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| template <typename T> struct SegmentTree{ struct node{ int l,r; T v,tag; }t[2000006*4]; T dat[2000006]; void pushup(int x){ t[x].v=op(t[x*2].v,t[x*2+1].v); } void build(int x,int l,int r){ t[x].l=l; t[x].r=r; if(l==r){ t[x].v=dat[l]; return; } int mid=(l+r)/2; build(x*2,l,mid); build(x*2+1,mid+1,r); pushup(x); } void pushdown(int x){ if(t[x].tag&&t[x].l!=t[x].r){ apply(x*2,t[x].tag); apply(x*2+1,t[x].tag); t[x].tag=0; } } void update(int x,int L,int R,T v){ int l=t[x].l,r=t[x].r; if(L<=l&&r<=R){ apply(x,v); return; } pushdown(x); int mid=(l+r)/2; if(L<=mid)update(x*2,L,R,v); if(mid+1<=R)update(x*2+1,L,R,v); pushup(x); } T query(int x,int L,int R){ int l=t[x].l,r=t[x].r; if(L<=l&&r<=R){ return t[x].v; } pushdown(x); int mid=(l+r)/2; T tot=tot_init; if(L<=mid)tot=q_op(tot,query(x*2,L,R)); if(mid+1<=R)tot=q_op(tot,query(x*2+1,L,R)); return tot; } T op(T x,T y){} T q_op(T x,T y){} T tot_init; void apply(int x,T v){} }; SegmentTree<int>SegTree;
|