树状数组

树状数组

模板

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