首页 > 编程语言 > 详细

树状数组

时间:2021-04-23 17:04:45      阅读:25      评论:0      收藏:0      [点我收藏+]
const ll N = 1333;
int n;
struct BIT {
    ll d[N][N];
    inline ll lowbit(ll x) {return -x&x;}
    void add (int x, int y, ll k) {
        for (int i = x; i <= n; i += lowbit(i)) {
            for (int j = y; j  <= n; j += lowbit(j)) {
                d[i][j] +=k;
            }
        }
    }
    ll ask(int x, int y) {
        ll ret = 0;
        for (int I = x; I >0; I -= lowbit(I)) {
            for (int J = y; J > 0; J -= lowbit(J)) {
                ret += d[I][J];
            }
        }
        return ret;
    }
}T;

树状数组

原文:https://www.cnblogs.com/Xiao-yan/p/14693415.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!