//`更新一个点`
void Update(int i, int j, int num) {
    int tempj;
    while( i <= Row ) {
        tempj = j;
        while( tempj <= Col ) {
            c[i][tempj] += num;
            tempj += Lowbit(tempj);
        }
        i += Lowbit(i);
    }
}
//`求区间和`
int Sum(int i, int j) {
    int tempj, sum = 0;
    while( i > 0 ) {
        tempj = j;
        while( tempj > 0 ) {
            sum += c[i][tempj];
            tempj -= Lowbit(tempj);
        }
        i -= Lowbit(i);
    }
    return sum;
}
예제 #3
0
int Sum(int end){//求前end项和
	int sum = 0;
	while(end > 0){
		sum += c[end];
		end -= Lowbit(end);
	}
	return sum;
}
//`求区间和`
int musum(int end) { //` 复杂度 O(logn)`
    int sum = 0;
    while (end > 0) {
        sum += m[end];
        end -= Lowbit(end);
    }
    return sum;
}
예제 #5
0
void plus(int pos,int num){//将第pos个元素更改为num
	while(pos <= n){//int n;
		c[pos] += num;
		pos += Lowbit(pos);
	}
}
//`修改一个位置的值`
void myplus(int pos) { //` 复杂度 O(logn)`
    while(pos <= mx) {
        m[pos] ++;
        pos += Lowbit(pos);
    }
}