首页 > 代码库 > [bzoj1452][JSOI2009]Count(树状数组)

[bzoj1452][JSOI2009]Count(树状数组)

1452: [JSOI2009]Count

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 2057  Solved: 1216
[Submit][Status][Discuss]

Description

技术分享

Input

技术分享

Output

技术分享

Sample Input

技术分享

Sample Output

1
2

HINT

 

技术分享

 

Source

 

裸得不能再裸了

暴力100个二维即可

技术分享
 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define LL long long 5 int n,m; 6 int lb(int x){ 7     return x&(-x); 8 } 9 int bit[110][310][310];10 int gra[310][310];11 int q(int v,int x,int y){12     int ans=0;13     for(int i=x;i;i-=lb(i)){14         for(int j=y;j;j-=lb(j)){15             ans+=bit[v][i][j];16         }17     }18     return ans;19 }20 int c(int v,int num,int x,int y){21     for(int i=x;i<=n;i+=lb(i)){22         for(int j=y;j<=n;j+=lb(j)){23             bit[v][i][j]+=num;24         }25     }26     return 0;27 }28 int main(){29     scanf("%d %d",&n,&m);30     for(int i=1;i<=n;i++){31         for(int j=1;j<=m;j++){32             int x;33             scanf("%d",&x);34             gra[i][j]=x;35             c(x,1,i,j);36         }37     }38     int Q;39     scanf("%d",&Q);40     while(Q--){41         int op;42         scanf("%d",&op);43         if(op==1){44             int x,y,v;45             scanf("%d %d %d",&x,&y,&v);46             c(v,1,x,y);47             c(gra[x][y],-1,x,y);48             gra[x][y]=v;49         }else{50             int x1,y1,x2,y2,v;51             scanf("%d %d %d %d %d",&x1,&x2,&y1,&y2,&v);52             x1--;53             y1--;54             printf("%d\n",q(v,x2,y2)-q(v,x2,y1)-q(v,x1,y2)+q(v,x1,y1));55         }56     }57     return 0;58 }
View Code

 

[bzoj1452][JSOI2009]Count(树状数组)