Description
There are many rook on a chessboard, a rook can attack the row and column it belongs, including its own place.
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
Input
The first line of the input is a integer
, meaning that there are
test cases.
Every test cases begin with four integers![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7b62c5ac964d1bbd8a6fa6db9499e998.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
.
is the number of Rook,
is the number of queries.
Then
lines follow, each contain two integers
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
describing the coordinate of Rook.
Then
lines follow, each contain four integers
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
describing the left-down and right-up coordinates of query.
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7b62c5ac964d1bbd8a6fa6db9499e998.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2ed2fdee3294209c466a113ffea668fe.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
.
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
.
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
.
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
Every test cases begin with four integers
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7b62c5ac964d1bbd8a6fa6db9499e998.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2ed2fdee3294209c466a113ffea668fe.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7b62c5ac964d1bbd8a6fa6db9499e998.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2ed2fdee3294209c466a113ffea668fe.png)
Then
![](https://i-blog.csdnimg.cn/blog_migrate/7b62c5ac964d1bbd8a6fa6db9499e998.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
Then
![](https://i-blog.csdnimg.cn/blog_migrate/2ed2fdee3294209c466a113ffea668fe.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7b62c5ac964d1bbd8a6fa6db9499e998.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2ed2fdee3294209c466a113ffea668fe.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/48fb42b8e72338f077d46e9ff74ffd93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
Output
For every query output "Yes" or "No" as mentioned above.
Sample Input
2 2 2 1 2 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 1 1 2 2 1 2 2
Sample Output
Yes
No
Yes
题解 :前缀和。前缀算法能够从一个给定数据空间中找出其前缀特征,即前缀集合。前缀集合具有确定性,能够匹配该前缀集合的数据一定属于该数据空间,否则将一定不属于该数据空间。
#include<cstdio>
#include<cstring>
using namespace std;
int ma[100100];
int mark[100100];
int main(){
int t,n,m,k,q,i,j;
int x,y,a,b,c,d;
scanf ("%d",&t);
while (t--){
scanf ("%d %d %d %d",&n,&m,&k,&q);
memset (mark,0,sizeof(mark));
memset (ma,0,sizeof(ma));
while (k--){
scanf ("%d %d",&x,&y);
mark[x]=1;//标记行
ma[y]=1;//标记列
}
for (i=1;i<=n;i++)
mark[i]+=mark[i-1];
for (j=1;j<=m;j++)
ma[j]+=ma[j-1];
while (q--){
scanf ("%d %d %d %d",&a,&b,&c,&d);
if (c-a+1==(mark[c]-mark[a-1])||(d-b+1)==(ma[d]-ma[b-1]))
printf ("Yes\n");
else
printf ("No\n");
}
}
return 0;
}