Kattis - intersectingrectangles 扫描线+线段树
题目: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 扫描线+线段树的更多相关文章
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- 【BZOJ3958】[WF2011]Mummy Madness 二分+扫描线+线段树
[BZOJ3958][WF2011]Mummy Madness Description 在2011年ACM-ICPC World Finals上的一次游览中,你碰到了一个埃及古墓. 不幸的是,你打开了 ...
- 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 ...
- 【bzoj4491】我也不知道题目名字是什么 离线扫描线+线段树
题目描述 给定一个序列A[i],每次询问l,r,求[l,r]内最长子串,使得该子串为不上升子串或不下降子串 输入 第一行n,表示A数组有多少元素接下来一行为n个整数A[i]接下来一个整数Q,表示询问数 ...
- hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积
题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> ...
- P3722 [AH2017/HNOI2017]影魔(单调栈+扫描线+线段树)
题面传送门 首先我们把这两个贡献翻译成人话: 区间 \([l,r]\) 产生 \(p_1\) 的贡献当且仅当 \(a_l,a_r\) 分别为区间 \([l,r]\) 的最大值和次大值. 区间 \([l ...
- BZOJ 2584: [Wc2012]memory(扫描线+线段树)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2584 题意:给出平面n个线段,任意两个线段严格不相交,且每个线段不平行于坐标轴.移 ...
- [BZOJ 1218] [HNOI2003] 激光炸弹 【n logn 做法 - 扫描线 + 线段树】
题目链接:BZOJ - 1218 题目分析 可以覆盖一个边长为 R 的正方形,但是不能包括边界,所以等价于一个边长为 R - 1 的正方形. 坐标范围 <= 5000 ,直接 n^2 的二维前缀 ...
- hdu4419 Colourful Rectangle 12年杭州网络赛 扫描线+线段树
题意:给定n个矩形,每个矩形有一种颜色,RGB中的一种.相交的部分可能为RG,RB,GB,RGB,问这n个矩形覆盖的面积中,7种颜色的面积分别为多少 思路:把x轴离散化做扫描线,线段树维护一个扫描区间 ...
随机推荐
- cf 766#
天呢,太垃圾了我.. AB懵逼了半天题意,C最后搞了个DP还不对...DP太垃圾了,, #include<bits/stdc++.h> #define INF 0x7fffffff #de ...
- 菜鸟理解Lamdba表达式
简单的说就是Java 1.8后给出个简化代码的方式, Java面向对象过分强调必须通过对象的形式来完成任务,而函数思想则尽量忽略面向对象的复杂语法,强调做什么,而不是以什么形式做. 举个栗子! 首先创 ...
- java集合对象实现原理
1.集合包 集合包是java中最常用的包,它主要包括Collection和Map两类接口的实现. 对于Collection的实现类需要重点掌握以下几点: 1)Collection用什么数据结构实现? ...
- Docker部署NETCORE应用程序
Docker部署NETCORE应用程序 创建.netcore项目,本文以ASP.NET Core2.2 版本为例 设置Dockerfile属性始终复制 编辑Dockerfile内容 FROM micr ...
- salt教程1-理解saltstack
https://docs.saltstack.com/en/getstarted/system/index.html 1 基本介绍 通过观察它的实际运行,你可以大致理解salt如何工作.这意味着,在控 ...
- springboot-jar
预览 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...
- mongodb与sql语句对比
左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * from users db.users.find({"age" ...
- MySQL 表查询语句练习题
MySQL 表查询语句练习题: 一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表 ...
- 基础nginx配置文件
nginx的配置文件很长,如果开始就看全部的话会懵逼,以下以最简单的配置文件来学习. 目标:定义一个虚拟主机127.0.0.1 端口是8080 [root@localhost conf]# cat ...
- 78.objects对象所属类原理分析
def index3(request): # 查找文章题目中包含中国的文章分类 category = Category.objects.filter(article__title__contains= ...