1 条题解
-
0
C++ :
#include<cstdio> using namespace std; int n,m,q; int c[350][350][105]; int a[350][350]; inline int lowbit(int x) { return x&(-x); } int first() { for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { c[i][j][0]=lowbit(i)*lowbit(j); } } } int change(int i,int j,int yuan,int xian) { int qx=i,qy=j; while(i<=n) { j=qy; while(j<=m) { c[i][j][yuan]--; c[i][j][xian]++; j+=lowbit(j); } i+=lowbit(i); } } int sum(int x,int y,int shu) { int result=0,qy=y; while(x>0) { y=qy; while(y>0) { result+=c[x][y][shu]; y-=lowbit(y); } x-=lowbit(x); } return result; } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%d",&a[i][j]); change(i,j,0,a[i][j]); } } scanf("%d",&q); int suit,x1,x2,y1,y2,p; for(int i=1;i<=q;i++) { scanf("%d",&suit); if(suit==1) { scanf("%d%d%d",&x1,&y1,&p); change(x1,y1,a[x1][y1],p); a[x1][y1]=p; } else { scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&p); printf("%d\n",sum(x2,y2,p)-sum(x1-1,y2,p)-sum(x2,y1-1,p)+sum(x1-1,y1-1,p)); } } }
- 1
信息
- ID
- 3329
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者