题目:https://open.kattis.com/problems/intersectingrectangles

题意::给你n个矩形,每一个矩形给你这个矩形的左下角的坐标和右上角的坐标,然后问你这些矩形会不会相交,如果存在相交的点,输出1,否则输出0。

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
const int M=2e5+;
struct node{
int l,r,h,flag;
}a[M];
bool cmp(node p,node q){
return p.h<q.h;
}
int lisan[M<<],tot1,tot2;
int tree[M<<];
void up(int root){
tree[root]=tree[root<<]+tree[root<<|];
}
void update(int p,int delta,int root,int l,int r)
{ if(l==r)
{
tree[root]+=delta;
return ;
}
int midd=(l+r)>>;
if(p<=midd)update(p,delta,lson);
else update(p,delta,rson);
up(root);
}
int query(int L,int R,int root,int l,int r)
{
if(L<=l&&r<=R)return tree[root];
//cout<<l<<"(("<<r<<endl;
int midd=(l+r)>>,res=;
if(L<=midd)res+=query(L,R,lson);
if(R>midd)res+=query(L,R,rson);
return res;
}
int main(){
int n;
scanf("%d",&n);
for(int x1,x2,y1,y2,i=;i<=n;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
a[++tot1]=node({x1,x2,y1,});///1代表上边界
a[++tot1]=node({x1,x2,y2,-});///-1代表下边界
// lisan[tot2++]=x1-1;
// lisan[tot2++]=x1+1;
lisan[++tot2]=x1;
// lisan[tot2++]=x2-1;
lisan[++tot2]=x2;
// lisan[tot2++]=x2+1;
}
// cout<<tot1<<"@@"<<tot2<<endl;
sort(a+,a++tot1,cmp); sort(lisan+,lisan+tot2+);
int m=unique(lisan+,lisan++tot2)-lisan-;
int ans=;
for(int i=;i<tot1;i++){
node u=a[i];
int x=lower_bound(lisan+,lisan++m,u.l)-lisan;
int y=lower_bound(lisan+,lisan++m,u.r)-lisan;
/// cout<<x<<"~~~"<<y<<endl;
if(u.flag==1)///因为是上边界,所以要在更新前加边,才不会误判
ans|=(query(x,y,,,*n)!=); update(x,u.flag,,,*n);
update(y,u.flag,,,*n);
if(u.flag==-)
ans|=(query(x,y,,,*n)!=);
}
printf("%d\n",ans!=);
return ;
}

Kattis - intersectingrectangles 扫描线+线段树的更多相关文章

  1. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  2. 【BZOJ3958】[WF2011]Mummy Madness 二分+扫描线+线段树

    [BZOJ3958][WF2011]Mummy Madness Description 在2011年ACM-ICPC World Finals上的一次游览中,你碰到了一个埃及古墓. 不幸的是,你打开了 ...

  3. HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)

    Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...

  4. 【bzoj4491】我也不知道题目名字是什么 离线扫描线+线段树

    题目描述 给定一个序列A[i],每次询问l,r,求[l,r]内最长子串,使得该子串为不上升子串或不下降子串 输入 第一行n,表示A数组有多少元素接下来一行为n个整数A[i]接下来一个整数Q,表示询问数 ...

  5. hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积

    题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> ...

  6. P3722 [AH2017/HNOI2017]影魔(单调栈+扫描线+线段树)

    题面传送门 首先我们把这两个贡献翻译成人话: 区间 \([l,r]\) 产生 \(p_1\) 的贡献当且仅当 \(a_l,a_r\) 分别为区间 \([l,r]\) 的最大值和次大值. 区间 \([l ...

  7. BZOJ 2584: [Wc2012]memory(扫描线+线段树)

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2584 题意:给出平面n个线段,任意两个线段严格不相交,且每个线段不平行于坐标轴.移 ...

  8. [BZOJ 1218] [HNOI2003] 激光炸弹 【n logn 做法 - 扫描线 + 线段树】

    题目链接:BZOJ - 1218 题目分析 可以覆盖一个边长为 R 的正方形,但是不能包括边界,所以等价于一个边长为 R - 1 的正方形. 坐标范围 <= 5000 ,直接 n^2 的二维前缀 ...

  9. hdu4419 Colourful Rectangle 12年杭州网络赛 扫描线+线段树

    题意:给定n个矩形,每个矩形有一种颜色,RGB中的一种.相交的部分可能为RG,RB,GB,RGB,问这n个矩形覆盖的面积中,7种颜色的面积分别为多少 思路:把x轴离散化做扫描线,线段树维护一个扫描区间 ...

随机推荐

  1. 04-String——课后动手动脑

    1.请运行以下示例代码StringPool.java,查看输出结果.如何解释这样的输出结果?从中你能总结出什么? public class StringPool { public static voi ...

  2. Spring(5) -(14) pointcut 语法

    AOP的规范本应该由SUM公司提出,但是被AOP联盟捷足先登.AOP联盟指定AOP规范,首先就要解决一个问题,怎么表示切入点,也就是在哪些方法上增强(where) AspectJ 是一个面向切面的框架 ...

  3. 使用Spring AOP实现MySql的读写分离

    转自:http://blog.csdn.net/xlgen157387/article/details/53930382 一.前言 分布式环境下数据库的读写分离策略是解决数据库读写性能瓶颈的一个关键解 ...

  4. expresscache和primocache加速资料整理-centos7缓存加速

    expresscache和primocachehttp://www.360doc.com/content/16/0111/17/256680_527142090.shtml 安装expresscach ...

  5. 实验吧web-易-FALSE

    先审计代码: <?php if (isset($_GET['name']) and isset($_GET['password'])) { if ($_GET['name'] == $_GET[ ...

  6. c++ rand随机数生成(随机种子设置)

    需求:每次初始化不同的随机数 1.默认 //这样用每次都会产生相同数字 #include <stdlib.h> #include <stdio.h> #define N 10 ...

  7. Linux学习-课后练习(第二章命令)20200216

  8. 51nod 1392:装盒子 匈牙利+贪心

    1392 装盒子 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  关注 有n个长方形盒子,第i个长度为Li,宽度为Wi,我们需要把他们套放.注意一个盒子 ...

  9. Java编译器 & Java解释器 & JVM

    转自:https://www.cnblogs.com/chengdabelief/p/6576320.html JVM JVM有自己完善的硬件架构,如处理器.堆栈(Stack).寄存器等,还具有相应的 ...

  10. 尝试解决 : Microsoft Visual C++ 14.0 is required 的问题

    当在pycharm  中安装  gevent 的时候 发生了  错误   晚上搜索的时候发现  解决问题有两种 方法 1  是   下载  whl  文件  通过二进制的方式 导入模块的包   想了想 ...