Conturbatio
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 786 Accepted Submission(s): 358
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?
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.
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
No
Yes
Huge input, scanf recommended.
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
const int N = ;
int flag_x[N],flag_y[N];
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
int n,m,k,q;
scanf("%d%d%d%d",&n,&m,&k,&q);
memset(flag_x,,sizeof(flag_x));
memset(flag_y,,sizeof(flag_y));
int x,y;
for(int i=;i<=k;i++){
scanf("%d%d",&x,&y);
flag_x[x] = ;
flag_y[y] = ;
}
for(int i=;i<=n;i++){
flag_x[i]+= flag_x[i-];
}
for(int i=;i<=m;i++){
flag_y[i] += flag_y[i-];
}
while(q--){
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(flag_x[x2]-flag_x[x1-]==x2-x1+||flag_y[y2]-flag_y[y1-]==y2-y1+) printf("Yes\n");
else printf("No\n");
}
}
return ;
}