Conturbatio
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 586 Accepted Submission(s): 274
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?
Input
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.
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
Hint
Huge input, scanf recommended.
题目大意:有t组测试数据,每组给一个n * m的矩形棋盘格子,棋盘内有很多车(x, y),每个车的攻击范围是这个车所在的行x和列y,共有K辆车,然后有Q次询问,每次询问给一个矩形(四个数描述矩形,左下角和右上角),问给的矩形的每个格子都能否被车攻击,是就输出“Yes”,否则“No”。
//机智的解法 ,参考大神的
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 100010
using namespace std;
int row[N],col[N];
int main()
{
int t,i;
scanf("%d",&t);
while(t--)
{
memset(row,0,sizeof(row));
memset(col,0,sizeof(col));
int n,m,k,q;
scanf("%d%d%d%d",&n,&m,&k,&q);
for(i=0;i<k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
row[x]=col[y]=1;//将车的点的横纵坐标标记为1.
}
for(i=1;i<=n;i++)//将车所在的行全标记为1。
if(row[i])
row[i]+=row[i-1];
for(i=1;i<=m;i++)//将车所在的列全标记为1.
if(col[i])
col[i]+=col[i-1];
for(i=0;i<q;i++)
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(row[x2]>=x2-x1+1||col[y2]>=y2-y1+1)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}