本文转载至点击打开链接
#include<stdio.h>
struct node{int x1,y1,x2,y2,c;
};
struct node s[1010];
int px[2010],py[2010],ux[10010],uy[10010],p[10000];
short a[2010][2010],c[2510];
int main(){int i,j,k,m,n; scanf("%d%d%d",&n,&m,&k);for(i=1;i<=k;i++)scanf("%d%d%d%d%d",&s[i].x1,&s[i].y1,&s[i].x2,&s[i].y2,&s[i].c);for(i=1;i<=k;i++){p[s[i].x1]=1;p[s[i].x2]=1;}p[n]=1;int sx=0,sy=0;for(i=1;i<=n;i++){if(p[i])px[++sx]=i;ux[i]=sx;}for(i=1;i<=m;i++)p[i]=0; for(i=1;i<=k;i++){p[s[i].y1]=1;p[s[i].y2]=1;} p[m]=1;for(i=1;i<=m;i++){if(p[i])py[++sy]=i;uy[i]=sy;}for(i=1;i<=k;i++)for(j=ux[s[i].x1];j<ux[s[i].x2];j++)for(int t=uy[s[i].y1];t<uy[s[i].y2];++t)a[j][t]=s[i].c;for(i=0;i<sx;i++)for(j=0;j<sy;j++) c[a[i][j]]+=(px[i+1]-px[i])*(py[j+1]-py[j]); c[1]=c[0];for(i=1;i<=2500;i++)if(c[i])printf("%d %d\n",i,c[i]);return 0;
}