Conturbatio
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 970 Accepted Submission(s): 438
Problem 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
T
, meaning that there are
T
test cases.
Every test cases begin with four integers n,m,K,Q .
K is the number of Rook, Q is the number of queries.
Then K lines follow, each contain two integers x,y describing the coordinate of Rook.
Then Q lines follow, each contain four integers x1,y1,x2,y2 describing the left-down and right-up coordinates of query.
1≤n,m,K,Q≤100,000 .
1≤x≤n,1≤y≤m .
1≤x1≤x2≤n,1≤y1≤y2≤m .
Every test cases begin with four integers n,m,K,Q .
K is the number of Rook, Q is the number of queries.
Then K lines follow, each contain two integers x,y describing the coordinate of Rook.
Then Q lines follow, each contain four integers x1,y1,x2,y2 describing the left-down and right-up coordinates of query.
1≤n,m,K,Q≤100,000 .
1≤x≤n,1≤y≤m .
1≤x1≤x2≤n,1≤y1≤y2≤m .
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 YesHintHuge input, scanf recommended.
Source
Recommend
<span style="font-family:SimSun;font-size:14px;background-color: rgb(255, 255, 255);">在一个<span class="katex" style="white-space: nowrap; line-height: 1.2;"></span></span><pre><span style="font-family:SimSun;font-size:14px;background-color: rgb(255, 255, 255);"><span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n \times m</span></span><span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-html" style="display: inline-block;"><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-style: italic;">n</span><span class="mbin" style="margin-left: 0.22222em;">×</span><span class="mord mathit" style="font-style: italic; margin-left: 0.22222em;">m</span></span></span></span>的国际象棋棋盘上有很多车(Rook),其中车可以攻击他所属的一行或一列,包括它自己所在的位置。 现在还有很多询问,每次询问给定一个棋盘内部的矩形,问矩形内部的所有格子是否都被车攻击到?<span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">Q</span></span><span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-html" style="display: inline-block;"><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-style: italic;">k为车的数量Q</span></span></span></span>为询问的</span>
个数。接下来有K行,每行两个整数x,y , 表示车所在的坐标。再接下来有Q行,每行4个整数x1,y1,x2,y2,表示询问的
矩形的左下角与右上角的坐标。
思路:如果只要是行能被全部攻击,或者列被全部攻击,那么所有的格子就能被全部攻击。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100010],b[100010];
int main()
{
int n,m,k,q,i,j,t;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%d%d%d%d",&n,&m,&k,&q);
for(i=0;i<k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
a[x]=1;
b[y]=1;
}
for(i=1;i<=n;i++)
a[i]+=a[i-1];
for(i=1;i<=m;i++)
b[i]+=b[i-1];
while(q--)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x2-x1+1==a[x2]-a[x1-1]||y2-y1+1==b[y2]-b[y1-1])
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}