复杂线段树模板

· · 个人记录

namespace SegmentTree {
    #define ls pos << 1
    #define rs pos << 1 | 1

    struct Node {} tr[N << 2];
    const Node empty = (Node){/**/};
    int add[N]; //懒标记,较多的时候开strct
    Node operator + (Node x, Node y)
    {
        if (x == empty) return y;
        if (y == empty) return x;
        /**/;
    }
    void pushup(int pos) {tr[pos] = tr[ls] + tr[rs];}
    void build(int l, int r, int pos)
    {
        tr[pos] = empty;
        if (l == r)
        {
            /**/;
            return;
        }
        int mid = (l + r) >> 1;
        build(l, mid, ls), build(mid + 1, r, rs);
        pushup(pos);
    }
    void lazy(int pos)
    {
        /**/;
    }
    void pushdown(int pos)
    {
        /**/;
    }
    void update(int l, int r, int pos, int L, int R)
    {
        if (L <= l && r <= R) return lazy(pos);
        pushdown(pos);
        int mid = (l + r) >> 1;
        if (L <= mid) update(l, mid, ls, L, R);
        if (mid < R) update(mid + 1, r, rs, L, R);
        pushup(pos);
    }
    Node query(int l, int r, int pos, int L, int R)
    {
        if (l == r) return tr[pos];
        pushdown(pos);
        int mid = (l + r) >> 1; Node ans = empty;
        if (L <= mid) ans = ans + query(l, mid, ls, L, R);
        if (mid < R) ans = ans + query(mid + 1, r, rs, L, R);
        return ans;
    }

    #undef ls
    #undef rs
}; using namespace SegmentTree;