P4054 [JSOI2009] 计数问题

#include 
using namespace std;
using PII = pair;
using ll  = long long;
using VI = vector;
using namespace std;

//a b
//c d
int n,m;
int g[310][310];
int tree[310][310][110];
int lowbit(int x){
    return x & -x;
}

int quary(int x,int y,int c){
    int res = 0;
    for(int i = x; i ; i -= lowbit(i)){
        for(int j = y; j ; j -= lowbit(j)){
            res += tree[i][j][c];
        }
    }
    return res;
}

void change(int x,int y,int k,int c){

    for(int i = x ; i <= n ; i += lowbit(i)){
        for(int j = y;j <= m; j += lowbit(j)){
            tree[i][j][c] += k;
        }
    }

}



int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int x;
            cin>>x;
            g[i][j] = x;
            change(i,j,1,x);
        }
    }
    int t;
    cin>>t;
    while(t--){
        int op;
        cin>>op;
        if(op == 1){
            int x,y,c;
            cin>>x>>y>>c;
            change(x,y,-1,g[x][y]);
            g[x][y] = c;
            change(x,y,1,c);
        }else{
            int c;
            int x1,x2,y1,y2;
            //1 1
            //2 1        2 2
            cin>>x1>>x2>>y1>>y2>>c;
            //cout<

二维树状数组,维护动态前缀和

你可能感兴趣的:(算法,c++,数据结构)