树状数组BIT——(板子)

单点修改

注意1:构造空间n

///注意1:构造空间n
struct BIT
{
    int n;
    vector<int>vec;
    BIT(int len=0)
    {
        n=len;
        vec.resize(n+1,0);
    }
    int pre(int x)
    {
        int sum=0;
        while(x)
            sum+=vec[x] , x-=lowbit(x);
        return sum;
    }
    void add(int x,int v)
    {
        while(x<=n)
            vec[x]+=v , x+=lowbit(x);
    }
    int segment_sum(int l,int r)
    {
        return pre(r)-pre(l-1);
    }
};
发布了149 篇原创文章 · 获赞 5 · 访问量 6908

猜你喜欢

转载自blog.csdn.net/weixin_44224825/article/details/104504095