题解:
二位树状数组
然后我开了300*300*300就T了
代码:
#include<bits/stdc++.h> using namespace std; const int N=305; int n,m,opt,z,a[N][N],dx,dy,x,y,f[N][N][105],q; int find(int x,int y,int z) { int ans=0; for (;x;x-=x&-x) for (int i=y;i;i-=i&-i) ans+=f[x][i][z]; return ans; } void insert(int x,int y,int z,int s) { for (;x<=n;x+=x&-x) for (int i=y;i<=m;i+=i&-i) f[x][i][z]+=s; } 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]),insert(i,j,a[i][j],1); scanf("%d",&q); while (q--) { scanf("%d",&opt); if (opt==1) { scanf("%d%d%d",&x,&y,&z); insert(x,y,a[x][y],-1); a[x][y]=z; insert(x,y,z,1); } if (opt==2) { scanf("%d%d%d%d%d",&x,&dx,&y,&dy,&z); printf("%d\n",find(dx,dy,z)-find(dx,y-1,z)-find(x-1,dy,z)+find(x-1,y-1,z)); } } }