E. Rooks and Rectangles

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/problemset/problem/524/E

Description

Polycarpus has a chessboard of size n × m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ​​the board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected.

Input

The first line contains four integers n, m, k and q (1 ≤ n, m ≤ 100 000, 1 ≤ k, q ≤ 200 000) — the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 ≤ x ≤ n, 1 ≤ y ≤ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ m). The corresponding rectangle area consists of cells (x, y), for which x1 ≤ x ≤ x2, y1 ≤ y ≤ y2. Strategically important areas can intersect of coincide.

Output

Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise.

Sample Input

4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3

Sample Output

YES
YES
NO

HINT

Picture to the sample: For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.

题意

给你,n个矩形,判断这个n个矩形是否被在矩形内的车全部覆盖

题解:

维护两个数据结构分别表示前i行里第几列是否被覆盖到和前i列里第j行是否被覆盖到

 
然后询问的时候就相当于查询第i1到第i2行这个区间的线段树中第j1到第j2列中最小的覆盖数是否为0,如果是就说明未被覆盖

思想比较麻烦,但是写起来特别快
 

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 500001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//**************************************************************************************
int a[maxn],n,m,k,q;;
struct node
{
int x,y;
};
node p[maxn];
struct pp
{
int x1,y1,x2,y2,id;
};
pp que[maxn]; void updata(int xx, int L, int R, int x, int val)
{
if(L==R)
{
a[xx]=val;
return;
}
int M=(L+R)>>;
if(x <= M)
updata(xx*,L,M,x,val);
else
updata(xx*+,M+,R,x,val);
a[xx]=min(a[xx*], a[xx*+]);
}
int query(int x, int L, int R, int l, int r)
{
if(l<=L&&R<=r)
return a[x];
int M=(L+R)>>;
if(r<=M)
return query(x*,L,M,l,r);
else if(l>M)
return query(x*+,M+,R,l,r);
else
return min(query(x*,L,M,l,r), query(x*+,M+,R,l,r));
}
bool cmp(node x,node y)
{
return x.x<y.x;
}
bool cmp1(pp x,pp y)
{
return x.x2<y.x2;
}
int ans[maxn];
void solve()
{
memset(a,,sizeof(a));
int pic=;
for(int i=;i<q;i++)
{
while(pic<k&&p[pic].x<=que[i].x2)
{
updata(,,m,p[pic].y,p[pic].x);
pic++;
}
if(query(,,m,que[i].y1,que[i].y2)>=que[i].x1)
ans[que[i].id]=;
}
}
void change()
{
swap(n,m);
for(int i=;i<k;i++)
swap(p[i].x,p[i].y);
sort(p,p+k,cmp);
for(int i=;i<q;i++)
{
swap(que[i].x1,que[i].y1);
swap(que[i].x2,que[i].y2);
}
sort(que,que+q,cmp1);
}
int main()
{ scanf("%d%d%d%d",&n,&m,&k,&q);
for(int i=;i<k;i++)
scanf("%d%d",&p[i].x,&p[i].y);
sort(p,p+k,cmp);
for(int i=;i<q;i++)
{
scanf("%d%d%d%d",&que[i].x1,&que[i].y1,&que[i].x2,&que[i].y2);
que[i].id=i;
}
sort(que,que+q,cmp1);
solve();
change();
solve();
for(int i=;i<q;i++)
{
if(ans[i])
puts("YES");
else
puts("NO");
}
}

VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值的更多相关文章

  1. VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线

    题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...

  2. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  3. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题

    E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  4. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp

    题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...

  5. VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串

    题目链接:http://codeforces.com/contest/533/problem/E E. Correcting Mistakes time limit per test 2 second ...

  6. Codeforces 524E Rooks and Rectangles 线段树

    区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define ...

  7. VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)

    VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  9. HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...

随机推荐

  1. [LeetCode] Intersection of Two Linked Lists 两链表是否相交

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  2. linux ip白名单、防火墙白名单 设置

    http://blog.csdn.net/catoop/article/details/50476099 登录信息在 /var/log/secure linux ip白名单 配置文件:/etc/hos ...

  3. 64.Minimum Path Sum---dp

    题目链接:https://leetcode.com/problems/minimum-path-sum/description/ 题目大意:从左上到右下的路径中,找出路径和最小的路径(与62,63题相 ...

  4. ACM ICPC Kharagpur Regional 2017

    ACM ICPC Kharagpur Regional 2017 A - Science Fair 题目描述:给定一个有\(n\)个点,\(m\)条无向边的图,其中某两个点记为\(S, T\),另外标 ...

  5. Asia-Dhaka 2017

    Asia-Dhaka 2017 A - Brick Walls 题目描述:如下图,编坐标与路径,给出两个坐标,问两个坐标的最短距离是多少. solution 先阶梯型地走,然后注意"中&qu ...

  6. SilverLight高亮显示文本

    文笔不好,就长话短说,就是想实现这样的效果,比如在成都二环路南一段一号附一号凤舞九天网吧 ,搜索 二环路 九天网吧 然后结果中高亮显示. <local:TextBlockHighLight Te ...

  7. [笔记]Linux NTP命令 (ESX适用)

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://delxu.blog.51cto.com/975660/307513 [推荐阅读] ...

  8. mac 安装mongodb与常用操作

    1.安装 brew update brew install mongodb 2.启动mongo mongod --config /usr/local/etc/mongod.conf 3.启动 mong ...

  9. IEnumerable的几个简单用法

    咋一看到IEnumerable这个接口,我们可能会觉得很神奇,在一般的编程时,基本上我们是想不到去用它的,可是,俗话说得好,存在便是道理,那么,它对我们来说,能够带来哪些奇妙的事情呢? 要想弄懂它,我 ...

  10. AC日记——松江1843路 洛谷七月月赛

    松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...