显示代码纯文本
#include<bits/stdc++.h>//浮水法..?第一次听诶
using namespace std;
int n,a,b,ans[1005],all;
struct Ques{
int x1,y1,x2,y2,col;
void read(){
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&col);
}
}q[1005];
bool check(int x1,int y1,int x2,int y2,int now){
if(x1>=q[now].x2)return 1;
if(x2<=q[now].x1)return 1;
if(y1>=q[now].y2)return 1;
if(y2<=q[now].y1)return 1;
return 0;
}
void cover(int x1,int y1,int x2,int y2,int now,int c){
if(x1==x2||y1==y2)return ;
while(now<=n&&check(x1,y1,x2,y2,now))now++;
if(now>n){
all+=(x2-x1)*(y2-y1);ans[c]+=(x2-x1)*(y2-y1);return ;
}
int tem1=max(x1,q[now].x1),tem2=max(y1,q[now].y1),tem3=min(x2,q[now].x2),tem4=min(y2,q[now].y2);
cover(x1,tem4,tem1,y2,now+1,c);cover(tem3,tem4,x2,y2,now+1,c);
cover(x1,y1,tem1,tem2,now+1,c);cover(tem3,y1,x2,tem2,now+1,c);
cover(tem1,tem4,tem3,y2,now+1,c);cover(x1,tem2,tem1,tem4,now+1,c);
cover(tem1,y1,tem3,tem2,now+1,c);cover(tem3,tem2,x2,tem4,now+1,c);
}
int main()
{
freopen("rect1.in","r",stdin);freopen("rect1.out","w",stdout);
scanf("%d%d%d",&a,&b,&n);
for(int i=1;i<=n;i++){
q[i].read();
}
for(int i=n;i>=1;i--){
cover(q[i].x1,q[i].y1,q[i].x2,q[i].y2,i+1,q[i].col);
}ans[1]+=a*b-all;
for(int i=1;i<=1000;i++){
if(ans[i])cout<<i<<" "<<ans[i]<<endl;
}
return 0;
}