escription
Input
Output
Sample Input
![](http://www.lydsy.com/JudgeOnline/images/1452_4.jpg)
Sample Output
1 2
HINT
——————————————————————————————————————————
这道题是裸的二维树状数组.....直接每个颜色弄一个二维的树状数组然后容斥(也不知道算不算)就可以辣
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#include#include #include int read(){ int ans=0,f=1,c=getchar(); while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();} return ans*f;}int n,m,q,k,f[357][357];int s[107][357][357];#define lowbit(x) x&-xvoid ins(int b[357][357],int x,int y,int v){ for(int i=x;i<=n;i+=lowbit(i)) for(int j=y;j<=m;j+=lowbit(j)) b[i][j]+=v;}int query(int b[357][357],int x,int y){ int sum=0; for(int i=x;i;i-=lowbit(i)) for(int j=y;j;j-=lowbit(j)) sum+=b[i][j]; return sum;}int main(){ int x1,y1,x2,y2,c; n=read(); m=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) k=read(),ins(s[k],i,j,1),f[i][j]=k; q=read(); for(int i=1;i<=q;i++){ k=read(); if(k==1){ x1=read(); y1=read(); c=read(); ins(s[f[x1][y1]],x1,y1,-1); f[x1][y1]=c; ins(s[f[x1][y1]],x1,y1,1); } else{ x1=read(); x2=read(); y1=read(); y2=read(); c=read(); printf("%d\n",query(s[c],x2,y2)-query(s[c],x2,y1-1)-query(s[c],x1-1,y2)+query(s[c],x1-1,y1-1)); } } return 0;}