小编ele*_*n22的帖子

x + = x&-x是什么意思?

我发现很多人使用x += x & -xx -= x & -x解决了区间树问题。你能解释一下这个方程的意思吗?

void update(int m, int x) { 
    m++;
    while (m < N) {
        t[m] = t[m] + x;
        m += m & -m;
    }
}
int query(int m) { 
    int result= 0;
    m++;
    while (m > 0) {
        result = result + t[m];
        m -= m & -m;
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

c++ algorithm tree bitwise-operators intervals

3
推荐指数
2
解决办法
141
查看次数

标签 统计

algorithm ×1

bitwise-operators ×1

c++ ×1

intervals ×1

tree ×1