bzoj1452: [JSOI2009]Count
二维BIT。。。
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,n) for(int i=1;i<=n;i++) #define clr(x,c) memset(x,c,sizeof(x)) int read(){ int x=0;char c=getchar(); while(!isdigit(c)){ c=getchar(); } while(isdigit(c)) x=x*10+c-'0',c=getchar(); return x; } const int nmax=305; const int maxn=105; #define lowbit(x) ((x)&-(x)) int g[nmax][nmax],n,m,q; struct node{ int a[nmax][nmax]; node(){clr(a,0);} void add(int x,int y,int v){ for(int i=x;i<=n;i+=lowbit(i)) for(int j=y;j<=m;j+=lowbit(j)) a[i][j]+=v; } int sum(int x,int y){ int ans=0; for(int i=x;i;i-=lowbit(i)) for(int j=y;j;j-=lowbit(j)) ans+=a[i][j]; return ans; } }; node nodes[maxn]; int main(){ n=read(),m=read(); rep(i,n) rep(j,m) g[i][j]=read(),nodes[g[i][j]].add(i,j,1); q=read(); rep(i,q){ int temp=read(); if(temp==1){ int u=read(),v=read(),d=read(); nodes[g[u][v]].add(u,v,-1); g[u][v]=d;nodes[d].add(u,v,1); }else{ int u=read(),d=read(),v=read(),w=read(),tmp=read(); printf("%d\n",nodes[tmp].sum(d,w)+nodes[tmp].sum(--u,--v)-nodes[tmp].sum(u,w)-nodes[tmp].sum(d,v)); } } return 0; }
1452: [JSOI2009]Count
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1932 Solved: 1148
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Sample Output
1
2
2
HINT