Monitor
s[i][j]表示i 行j列所有面积之和,二维前缀和
代码语言:javascript复制#include <bits/stdc .h>
using namespace std;
int main()
{
int n, m, q, a, b, c, d;
while (scanf("%d%d", &n, &m) > 0)
{
int s[n 5][m 5];
memset(s, 0, sizeof(s));
scanf("%d", &q);
while (q--)
{
scanf("%d%d%d%d", &a, &b, &c, &d);
s[a][b] ;
s[c 1][d 1] ;
s[a][d 1]--;
s[c 1][b]--;
}
for(int i=1;i<=n;i )
for(int j=1;j<=m;j )
s[i][j] = s[i][j] s[i-1][j] s[i][j-1] - s[i-1][j-1];
for(int i=1;i<=n;i )
for(int j=1;j<=m;j )
if(s[i][j]>0)
s[i][j] = 1;
for(int i=1;i<=n;i )
for(int j=1;j<=m;j )
s[i][j] = s[i][j] s[i-1][j] s[i][j-1] - s[i-1][j-1];
scanf("%d", &q);
while (q--)
{
scanf("%d%d%d%d", &a, &b, &c, &d);
if ((c - a 1) * (d - b 1) == s[c][d] - s[a - 1][d] - s[c][b - 1] s[a - 1][b - 1])
printf("YESn");
else
printf("NOn");
}
}
}