首页 > 编程语言 > 详细

树状数组

时间:2020-04-05 17:40:43      阅读:50      评论:0      收藏:0      [点我收藏+]

树状数组

模板

int c[maxn * 2];
int lowbit(int x) {
    return x & (-x);
}

void add(int i,int d) {
    while(i<maxn*2) {
        c[i] += d;
        i += lowbit(i);
    }
}

int query(int i) {
    int ret = 0;
    while(i>0) {
        ret += c[i];
        i -= lowbit(i);
    }
    return ret;
}

树状数组

Pair of Topics

https://codeforces.com/contest/1324/problem/D

题意

给定\(a,b\)序列,求有多少对\(i<j\)\(a_i+a_j>b_i+b_j\)

解法1:按照值从大到小插入
代码 : https://xlorpaste.cn/2rdsp4

解法2:按照序列顺序从小到大
代码 : https://xlorpaste.cn/3vucur

打一顿!!不用树状数组
代码 : https://xlorpaste.cn/5oto9y

树状数组

原文:https://www.cnblogs.com/guaguastandup/p/12637750.html

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