/*
思路就是枚举矩形下面那条先,把所有和其交叉的竖线更新进线段树,然后扫描先向上更新,遇到竖线上端点就在线段树里删掉,遇到横线就更新答案
*/
#include<bits/stdc++.h>
using namespace std;
#define N 20005
#define ll long long struct SegV{int x,y1,y2;}v[N];//垂直线
struct SegH{int y,x1,x2;}h[N];//水平线
int cmp(SegH a,SegH b){return a.y<b.y;} int n,cntv,cnth;
int y[N],cnty,x[N],cntx;
vector<SegV>Up[N],Down[N]; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[N<<];
void update(int pos,int v,int l,int r,int rt){
if(l==r){sum[rt]+=v;return;}
int m=l+r>>;
if(pos<=m)update(pos,v,lson);
else update(pos,v,rson);
sum[rt]=sum[rt<<]+sum[rt<<|];
}
int query(int L,int R,int l,int r,int rt){
if(L<=l && R>=r)return sum[rt];
int m=l+r>>,res=;
if(L<=m)res+=query(L,R,lson);
if(R>m)res+=query(L,R,rson);
return res;
}
int main(){
cin>>n;
for(int i=;i<=n;i++){
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
x[++cntx]=x1;x[++cntx]=x2;
y[++cnty]=y1;y[++cnty]=y2;
if(x1==x2){//垂直线
cntv++;
v[cntv].x=x1;
v[cntv].y1=min(y1,y2);
v[cntv].y2=max(y1,y2);
}
else {
cnth++;
h[cnth].y=y1;
h[cnth].x1=min(x1,x2);
h[cnth].x2=max(x1,x2);
}
} sort(x+,x++cntx);
cntx=unique(x+,x++cntx)-x-;
sort(y+,y++cnty);
cnty=unique(y+,y++cnty)-y-; for(int i=;i<=cnth;i++){
h[i].y=lower_bound(y+,y++cnty,h[i].y)-y;
h[i].x1=lower_bound(x+,x++cntx,h[i].x1)-x;
h[i].x2=lower_bound(x+,x++cntx,h[i].x2)-x;
}
for(int i=;i<=cntv;i++){
v[i].x=lower_bound(x+,x++cntx,v[i].x)-x;
v[i].y1=lower_bound(y+,y++cnty,v[i].y1)-y;
v[i].y2=lower_bound(y+,y++cnty,v[i].y2)-y;
} sort(h+,h++cnth,cmp);//给水平线从低到高排序
for(int i=;i<=cntv;i++){//按端点处理垂直线
Up[v[i].y2].push_back(v[i]);
Down[v[i].y1].push_back(v[i]);
} long long ans=;
for(int i=;i<=cnth;i++){
memset(sum,,sizeof sum);
//把所有和h[i]交叉的竖线更新进线段树
for(int j=;j<=cntv;j++)
if(v[j].y1<=h[i].y && v[j].y2>=h[i].y)
update(v[j].x,,,cntx,);
//开始向上枚举所有水平线
int now=h[i].y;//当前的高度
for(int j=i+;j<=cnth;j++)if(h[i].y!=h[j].y){
while(now+<=h[j].y){
++now;
for(auto v:Up[now-]){//把这个高度以下的都删掉
if(v.y1<=h[i].y)
update(v.x,-,,cntx,);
}
}
int L=max(h[i].x1,h[j].x1),R=min(h[i].x2,h[j].x2);
if(L<=R){
int res=query(L,R,,cntx,);
ans+=res*(res-)/;
}
}
}
cout<<ans<<endl;
}

暴力枚举+扫描线+线段树——cf1194E的更多相关文章

  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. P3722 [AH2017/HNOI2017]影魔(单调栈+扫描线+线段树)

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

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

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

  4. 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 ...

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

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

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

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

  7. 【BZOJ 4059】 (分治暴力|扫描线+线段树)

    4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 632  Solved: 22 ...

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

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

  9. [矩形并-扫描线-线段树]Picture

    最近在补数学和几何,没啥好写的,因为已经决定每天至少写一篇了,今天随便拿个题水水. 题目大意:给你N个边平行于坐标轴的矩形,求它们并的周长.(N<=5000) 思路:这个数据范围瞎暴力就过了,但 ...

随机推荐

  1. hdu 5885 XM Reserves (FFT建模)

    Problem Description As an eligible Ingress Resistance Agent you should know your power source, the E ...

  2. APICloud框架——总结一下最近开发APP遇到的一些问题 (二)

    高度自适应 flex布局 允许子元素伸缩 手机号正则 function checkPhone(data){ if(!(/^1[34578]\d{9}$/.test(data))){ alert(&qu ...

  3. MD5、SHA1、DES加密和解密,Base64编码解码

    /// <summary> /// EncryptHelper 来自 www.Admin10000.com /// </summary> public class Encryp ...

  4. vuedraggable 实现拖动数据改变

    // 引入组件 import Draggable from 'vuedraggable' // 使用组件 DragList 为自己封装好的组件 注意一定要使用vue的sync <DragList ...

  5. 提供 web前端、H5、html页面 技术服务

    如有前端页面的需求请在评论区留言  第一时间进行回复

  6. html{-webkit-text-size-adjust:none;}(取消浏览器最小字体限制)

    2016年10月13日 09:31:58 ITzhongzi 阅读数 9409   1.当样式表里font-size<12px时,中文版chrome浏览器里字体显示仍为12px,这时可以用 ht ...

  7. Unicode数据类型的是是非非(转)

    转:http://cio.chinabyte.com/344/9002344.shtml 在SQL Server数据库中,数据类型主要分为两类,分别为Unicode数据类型与非Unicode数据类型. ...

  8. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  9. LCD中6800和8080的区别【转】

    8080是通过“读使能(RE)”和“写使能(WE)”两条控制线进行读写操作6800是通过“总使能(E)”和“读写选择(W/R)”两条控制线进行 很多MCU或者LCD模块外部接口一般采用并行方式,并行接 ...

  10. 记录以下mysql5.7在win使用Navicat无法链接的问题

    1.前提 系统:win1o0 局域网服务器:ubuntu18.04 mysql版本:5.7 问题描述: 在ubuntu18.04下的shell 中使用mysql -uroot  -p  是可以登陆的, ...