分析:运用扫描线,先从左到右扫描,用纵坐标进行建树,

随着扫描线的右向右移动。不断更新横坐标小于扫描线的车

更新的时候  在树中更新车的纵坐标的位置,把该位置的值变成该车的横坐标

线段树维护的是区间最大值和最小值

这样每到一个矩形区域的右边界,查询该区间的纵坐标区间内的最大值和最小值

如果最大值小于右边界,最小值大于左边界

那么这个矩形区域内每一行都可以被矩形区域内的车覆盖,标记一下

同理,从下到上扫描,可以找到符合条件的矩形

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=2e5+;
int n,m,k,q;
struct Rec
{
int x1,x2,y1,y2,id;
bool operator<(const Rec &e)const
{
return x2<e.x2;
}
} o[N];
bool cmp1(Rec a,Rec b)
{
return a.x2<b.x2;
}
bool cmp2(Rec a,Rec b)
{
return a.y2<b.y2;
}
struct Point
{
int x,y;
} p[N];
bool cmp3(Point a,Point b)
{
return a.x<b.x;
}
bool cmp4(Point a,Point b)
{
return a.y<b.y;
}
int c[N<<],b[N<<];
void build(int rt,int l,int r)
{
b[rt]=c[rt]=N;
if(l==r)return;
int mid=(l+r)>>;
build(rt*,l,mid);
build(rt*+,mid+,r);
}
void pushup(int rt)
{
c[rt]=min(c[rt*],c[rt*+]);
b[rt]=max(b[rt*],b[rt*+]);
}
void update(int rt,int l,int r,int pos,int t)
{
if(l==r)
{
b[rt]=c[rt]=t;
return;
}
int mid=(l+r)>>;
if(pos<=mid)update(rt*,l,mid,pos,t);
else update(rt*+,mid+,r,pos,t);
pushup(rt);
}
int querymin(int rt,int l,int r,int x,int y)
{
if(x<=l&&r<=y)
return c[rt];
int res=N;
int mid=(l+r)>>;
if(x<=mid)res=min(res,querymin(rt*,l,mid,x,y));
if(y>mid)res=min(res,querymin(rt*+,mid+,r,x,y));
return res;
}
int querymax(int rt,int l,int r,int x,int y)
{
if(x<=l&&r<=y)
return b[rt];
int res=-;
int mid=(l+r)>>;
if(x<=mid)res=max(res,querymax(rt*,l,mid,x,y));
if(y>mid) res=max(res,querymax(rt*+,mid+,r,x,y));
return res;
}
bool ans[N];
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);
for(int i=; i<=q; ++i)
scanf("%d%d%d%d",&o[i].x1,&o[i].y1,&o[i].x2,&o[i].y2),o[i].id=i;
sort(p+,p++k,cmp3);
sort(o+,o++q,cmp1);
int cnt=;
build(,,m);
for(int i=; i<=q; ++i)
{
for(; cnt<=k&&p[cnt].x<=o[i].x2; ++cnt)
update(,,m,p[cnt].y,p[cnt].x);
int a1=querymin(,,m,o[i].y1,o[i].y2);
int a2=querymax(,,m,o[i].y1,o[i].y2);
if(a1>=o[i].x1&&a2<=o[i].x2)
ans[o[i].id]=;
}
sort(p+,p+k+,cmp4);
sort(o+,o++q,cmp2);
build(,,n),cnt=;
for(int i=; i<=q; ++i)
{
for(; cnt<=k&&p[cnt].y<=o[i].y2; ++cnt)
update(,,n,p[cnt].x,p[cnt].y);
int a1=querymin(,,n,o[i].x1,o[i].x2);
int a2=querymax(,,n,o[i].x1,o[i].x2);
if(a1>=o[i].y1&&a2<=o[i].y2)
ans[o[i].id]=;
}
for(int i=; i<=q; ++i)
if(ans[i])printf("YES\n");
else printf("NO\n");
return ;
}

CDOJ 1071 秋实大哥下棋 线段树的更多相关文章

  1. uestc 1073 秋实大哥与线段树 Label:线段树

    秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) “学习本无底, ...

  2. UESTC_秋实大哥与线段树 2015 UESTC Training for Data Structures<Problem M>

    M - 秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  3. UESTC_秋实大哥下棋 2015 UESTC Training for Data Structures<Problem I>

    I - 秋实大哥下棋 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  4. CDOJ 1057 秋实大哥与花 线段树 区间更新+区间查询

    链接: I - 秋实大哥与花 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  5. CDOJ 1060 秋实大哥与快餐店 字典树 水题

    题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Sub ...

  6. CDOJ 1070 秋实大哥打游戏 带权并查集

    链接 F - 秋实大哥打游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  7. CDOJ 1069 秋实大哥去打工 单调栈 下标处理

    E - 秋实大哥去打工 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit St ...

  8. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  9. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

随机推荐

  1. 关于NPC和NP-Hard问题

    参考链接: 1. P.NP.NPC和NP-hard问题的理解 参考:<算法导论>

  2. Jquery Offset, Document, Window 都是什么

    From http://www.cnblogs.com/luhe/archive/2012/11/14/2769263.html   JQuery Offset实验与应用 我们有时候需要实现这样一种功 ...

  3. 如何在Exe和BPL插件中实现公共变量共享及窗口溶入技术Demo源码

    如何在Exe和BPL插件中实现公共变量共享及窗口溶入技术Demo源码 1.Delphi编译方式介绍: 当我们在开发一个常规应用程序时,Delphi可以让我们用两种方式使用VCL,一种是把VCL中的申明 ...

  4. 【BZOJ】1002: [FJOI2007]轮状病毒 递推+高精度

    1002: [FJOI2007]轮状病毒 Description 给定n(N<=100),编程计算有多少个不同的n轮状病毒. Input 第一行有1个正整数n. Output 将编程计算出的不同 ...

  5. EasyUI portal自定义小图标,不是用js方式加载

    <script src="~/Scripts/jquery.portal.js"></script> <script> $(function ( ...

  6. WindowsPhone客户端第一次审核失败记录

    微软返回失败pdf,其中2.7.2和2.7.3没有通过,原因是: 1. 没有提供隐私策略,所以在提交App要填写的隐私策略url里加了隐私策略的网址链接. 2. 由于使用了定位服务,所以第一次进入应用 ...

  7. aircrack-ng on OSX 从零开始之安装

    今天在知乎上看到了Evil1m0在知乎上写的一个关于无线网入侵的帖子,激起我也想折腾一下想法.其实这个想法已经由来已久了.如今WIFI遍地都有,这里面的安全隐患我真心觉得太大.实在需要舆论来给大家普及 ...

  8. centos 卸载vsftpd方法

    centos 卸载vsftpd方法 在服务器上安装了vsftpd,配置出错需要卸载vsftpd.卸载vsftpd的命令如下: 1 [root@localhost ~]# rpm -aq vsftpd2 ...

  9. uva 1475 - Jungle Outpost

    半平面交,二分: 注意,题目的点是顺时针给出的: #include<cstdio> #include<algorithm> #include<cmath> #def ...

  10. http://blog.sina.com.cn/s/blog_7caae74b0100zl17.html

    http://blog.sina.com.cn/s/blog_7caae74b0100zl17.html