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

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

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

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

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

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

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

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

#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. parseInt()、parseFloat()与Number()的比较

    我有一个同学最近在自学JavaScript,偶尔遇到问题了会让我帮忙解决,虽然我也是一个JavaScript菜鸟,但是我还是很乐意帮忙,这样不仅可以帮到别人,也可以让自己在解决问题的过程中学到更多知识 ...

  2. jQuery 选择器(转)

    jQuery 选择器 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" 的元 ...

  3. jQuery入门[1]-构造函数【转载】

    最近看了一些jquery的进阶教程,感觉很不错,与大家分享下! jQuery——构造函数 ◦体积小(v1.2.3 15kb)◦丰富的DOM选择器(CSS1-3 + XPath) ◦跨浏览器(IE6,F ...

  4. PHP上传文件大小限制问题 post_max_size对大小的影响及解决方法

    今天在操作php上传的时候发现了一个问题,就是当php脚步上传的文件大小超过php.ini中post_max_size的限制的时候页面不会给出提醒,文件也上传失败,这个问题感觉应该算是一个另类,今天跟 ...

  5. json 包含字段及函数的写法

    在javascript中写类有多种方式: 1.function()中嵌套function; 2.prototype的方式 ,3.json的方式,如下: <script language=&quo ...

  6. SD卡FAT32文件系统格式

    一.声明 1.本文来源和主旨 2.本文测试环境 二.SD卡FAT文件系统 1.SD卡FAT32文件系统的整体布局 2.FAT文件系统简介 ① 文件分配表 ② 目录项 三.DBR(DOS BOOT RE ...

  7. C++ new operator, delete operator, operator new, operator delete, new placement

    http://www.younfor.com/cpp-new-placement-new-operator-new.html http://www.cnblogs.com/luxiaoxun/arch ...

  8. urllib2.urlopen超时问题

    urllib2.urlopen超时问题 没有设置timeout参数,结果在网络环境不好的情况下,时常出现read()方法没有任何反应的问题,程序卡死在read()方法里,搞了大半天,才找到问题,给ur ...

  9. IBM

    http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1306mongodb2/

  10. SQLite入门与分析(六)---再谈SQLite的锁

    写在前面:SQLite封锁机制的实现需要底层文件系统的支持,不管是Linux,还是Windows,都提供了文件锁的机制,而这为SQLite提供了强大的支持.本节就来谈谈SQLite使用到的文件锁——主 ...