Those clever but useless on the tree line

Contents: I'm on the right

Those clever but useless on the tree line

If you do not segment tree, poke here

Maintenance Interval max / min values:

This is push_up () easy to understand.

void push_up(int rt) {
    tree[rt].max = max(tree[lson].max, tree[rson].max);
    tree[rt].min = min(tree[lson].min, tree[rson].min);
}

Achievements when he did build, push_down time to look at the max and min are changed lazy on the line.
Sometimes less than push_down ();

Interval Query max / min values

Also easy to understand, and seek the interval and the same.
There modify operation can be added when pushd_down ();

int query_max(int rt, int l, int r, int L, int R) {
    if (L <= l && r <= R) return tree[rt].max;
    int mid = (l + r) >> 1, maxn = -1;
    if (L <= mid) maxn = max(maxn, query_max(lson, l, mid, L, R));
    if (R > mid) maxn = max(maxn, query_max(rson, mid + 1, r, L, R));
    return maxn;
}

+ Maintenance interval and the square root zone.

That's a good question
strongly recommended cancer GSS data structure can be found to the Luo Valley, it will be done after feeling their thinking has been sublimated.
A refreshing a problem, A two questions never tired, A Sa question of immortality
Because a large integer \ (\ sqrt {\ sqrt { \ sqrt {\ sqrt {\ sqrt {\ sqrt {n}}}}}} = 1 \) we can determine what the lazy interval had several, if more than equal to 6, then there is no need to engage in (but I did not write)
and the square root of time to determine what the maximum range is not 1, if the maximum interval is 1, then the other must also be 1, there is no need in prescribing the.

About Update:

void update(int L, int R, int l, int r, int rt) {
    if (l == r) {
        t[rt].sum = sqrt(t[rt].sum);
        t[rt].mx = sqrt(t[rt].mx);
        return ;
    }
    int m = (l + r) >> 1;
    if (L <= m && t[lson].mx > 1) update(L, R, l, m, lson);
    if (R > m && t[rson].mx > 1) update(L, R, m + 1, r, rson);
    pushup(rt);
}

Queries do not have to say it, and seek maximum range, like ah.

The largest sub-segment and range.

Good question can be said to be a bare title.
The difficulty is push_up and query

push_up

void push_up(int rt) {
    tree[rt].sum = tree[lson].sum + tree[rson].sum;//这就是普通的区间和
    
    tree[rt].qian = max(tree[lson].qian, tree[lson].sum + tree[rson].qian);
    tree[rt].hou = max(tree[rson].hou, tree[rson].sum + tree[lson].hou);
    //区间的前缀和的最大值就是左区间的前缀和和(右区间的全缀合加上左区间的和)取max
    //区间后缀和类比可得
    tree[rt].zi = max(tree[lson].zi, tree[rson].zi);
    tree[rt].zi = max(tree[rt].zi, tree[lson].hou + tree[rson].qian);
    //最大子段和就是左右区间最大子段和,还有左区间后缀和加上右区间前缀和取max
}

About query:

node unioc(node a, node b) {
    node ans;//区间合并可类比push_up
    ans.sum = a.sum + b.sum;
    ans.zi = max(a.zi, b.zi);
    ans.zi = max(a.hou + b.qian, ans.zi);
    ans.qian = max(a.qian, a.sum + b.qian);
    ans.hou = max(b.hou, b.sum + a.hou);
    return ans;
}

node query(int rt, int l, int r, int L, int R) {
    if (L <= l && r <= R) return tree[rt];
    int mid = (l + r) >> 1;
    if (L > mid) return query(rson, mid + 1, r, L, R);//如果这个区间都在右边,直接在右边算就行
    if (R <= mid) return query(lson, l, mid, L, R);//争端区间都在左边
    return unioc(query(lson, l, mid, L, R), query(rson, mid + 1, r, L, R));//如果两端都有那么还要合并区间.
}

Plus range modification becomes this question
is also very simple, as long as you would a top that.
Interval modification is also quite simple. Easy to understand.

void change(int rt, int c, int l, int r, int pos) {
    if (l == r) {
        tree[rt].sum = tree[rt].ls = tree[rt].rs = tree[rt].mis = c;
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid) change(lson, c, l, mid, pos);
    if (pos > mid) change(rson, c, mid + 1, r, pos);
    push_up(rt);
}

Guess you like

Origin www.cnblogs.com/zzz-hhh/p/12214977.html