#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int f[303][303][100],n,m; int c[303][303]; int lowbit(int x) { return x&(-x); } void change(int x,int y,int l,int v) { for (int i=x;i<=n;i+=lowbit(i)) for (int j=y;j<=m;j+=lowbit(j)) f[i][j][l]+=v; } int sum(int x,int y,int k) { int ans=0; for (int i=x;i>=1;i-=lowbit(i)) for (int j=y;j>=1;j-=lowbit(j)) ans+=f[i][j][k]; return ans; } int main() { freopen("a.in","r",stdin); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { int x; scanf("%d",&x); c[i][j]=x; change(i,j,x,1); } int t; scanf("%d",&t); for (int i=1;i<=t;i++) { int op; int x,y,z,w,k; scanf("%d",&op); if (op==1) { scanf("%d%d%d",&x,&y,&k); change(x,y,c[x][y],-1); change(x,y,k,1); c[x][y]=k; } else { scanf("%d%d%d%d%d",&x,&z,&y,&w,&k); int a=sum(z,w,k); int b=sum(x-1,w,k); int c=sum(z,y-1,k); int d=sum(x-1,y-1,k); printf("%d\n",a-b-c+d); } } }