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

1452: [JSOI2009]Count

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

Description

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

Input

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

Output

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

Sample Input

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

Sample Output

1
2

HINT

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

Source

裸得不能再裸了

暴力100个二维即可

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LL long long
int n,m;
int lb(int x){
return x&(-x);
}
int bit[][][];
int gra[][];
int q(int v,int x,int y){
int ans=;
for(int i=x;i;i-=lb(i)){
for(int j=y;j;j-=lb(j)){
ans+=bit[v][i][j];
}
}
return ans;
}
int c(int v,int num,int x,int y){
for(int i=x;i<=n;i+=lb(i)){
for(int j=y;j<=n;j+=lb(j)){
bit[v][i][j]+=num;
}
}
return ;
}
int main(){
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int x;
scanf("%d",&x);
gra[i][j]=x;
c(x,,i,j);
}
}
int Q;
scanf("%d",&Q);
while(Q--){
int op;
scanf("%d",&op);
if(op==){
int x,y,v;
scanf("%d %d %d",&x,&y,&v);
c(v,,x,y);
c(gra[x][y],-,x,y);
gra[x][y]=v;
}else{
int x1,y1,x2,y2,v;
scanf("%d %d %d %d %d",&x1,&x2,&y1,&y2,&v);
x1--;
y1--;
printf("%d\n",q(v,x2,y2)-q(v,x2,y1)-q(v,x1,y2)+q(v,x1,y1));
}
}
return ;
}
上一篇:1305 Pairwise Sum and Divide


下一篇:cobbler koan自动重装系统