MonitorTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others)Total Submission(s): 514 Accepted Submission(s): 160 Problem Description Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×m . Input There are mutiple test cases. Output For each case you should print q lines. Sample Input 6 6 3 2 2 4 4 3 3 5 6 5 1 6 2 2 3 2 5 4 1 5 6 5 Sample Output YES NO Hint In the picture,the red solid rectangles mean the monitor Xiaoteng installed, and the blue dotted rectangles mean the area will be stolen. |
在一个面积不超过n*m的矩形上,有p个矩形A,问之后的矩形B能否被之前的A全部覆盖(每个B的点都在至少一个A中)
考虑二维差分前缀和
由于不清楚n m的具体范围,所以动态内存开二维数组
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int **a;
a=(int**)malloc(sizeof(int*)*(n+10));
for(int i=0;i<n+10;i++) a[i]=(int*)malloc(sizeof(int)*(m+10));
for(int i=0;i<n+10;i++) for(int j=0;j<m+10;j++) a[i][j]=0;
int k;scanf("%d",&k);
for(int i=0;i<k;i++)
{
int x1,y1,x2,y2,p=1;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
a[x1][y1]+=p;a[x2+1][y2+1]+=p;
a[x2+1][y1]-=p;a[x1][y2+1]-=p;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
a[i][j]+=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
if(a[i][j]) a[i][j]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
a[i][j]+=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
} int q;
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int ans=a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
if(ans==(x2-x1+1)*(y2-y1+1))
printf("YES\n");
else
printf("NO\n");
}
}
}