【BZOJ4418】[Shoi2013]扇形面积并 扫描线+线段树
【BZOJ4418】[Shoi2013]扇形面积并
Description
Input
Output
Sample Input
3 8 2
1 -8 8
3 -7 3
5 -5 5
【输入样例2】
2 4 1
4 4 2
1 -4 4
Sample Output
76
【输出样例2】
98
HINT
对于100%的数据,1≤n≤10^5, 1≤m≤10^6,1≤k≤5000,1≤ri≤10^5,-m≤a1,a2≤m
题解:现将扇形掰开变成矩形,然后用扫描线处理,每个矩形都改成差分的形式。由于对于任意一条与x轴垂直的先,里面的点被覆盖的层数一定不会比外面少,所以我们可以在线段树上二分,时间复杂度$O(nlogr)$。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lson x<<1
#define rson x<<1|1
using namespace std; const int maxn=100010;
typedef long long ll;
int n,m,tot,R,K;
int s[maxn<<2];
ll ans;
struct node
{
int x,y,k;
node() {}
node(int a,int b,int c) {x=a,y=b,k=c;}
}p[maxn<<2];
bool cmp(const node &a,const node &b)
{
return a.x<b.x;
}
inline void pushup(int x)
{
s[x]=s[lson]+s[rson];
}
void updata(int l,int r,int x,int a,int b)
{
s[x]+=b;
if(l==r) return ;
int mid=(l+r)>>1;
if(a<=mid) updata(l,mid,lson,a,b);
else updata(mid+1,r,rson,a,b);
}
int query(int l,int r,int x,int a)
{
if(l==r) return l;
int mid=(l+r)>>1;
if(s[rson]>=a) return query(mid+1,r,rson,a);
return query(l,mid,lson,a-s[rson]);
}
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+(gc^'0'),gc=getchar();
return ret*f;
}
int main()
{
n=rd(),m=rd(),K=rd();
int i,a,b,c;
for(i=1;i<=n;i++)
{
c=rd(),a=rd()+m,b=rd()+m,R=max(R,c);
if(a<=b) p[++tot]=node(a,c,1),p[++tot]=node(b,c,-1);
else p[++tot]=node(a,c,1),p[++tot]=node(2*m,c,-1),p[++tot]=node(0,c,1),p[++tot]=node(b,c,-1);
}
sort(p+1,p+tot+1,cmp);
for(i=1;i<=tot;i++)
{
a=query(0,R,1,K),ans+=(ll)a*a*(p[i].x-p[i-1].x);
updata(0,R,1,p[i].y,p[i].k);
}
printf("%lld",ans);
return 0;
}
【BZOJ4418】[Shoi2013]扇形面积并 扫描线+线段树的更多相关文章
- POJ1151Atlantis 矩形面积并 扫描线 线段树
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ1151 题意概括 给出n个矩形,求他们的面积并. n<=100 题解 数据范围极小. 我们分3种 ...
- bzoj4418 [Shoi2013]扇形面积并
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4418 [题解] 被题目名称吓死系列. 用一棵线段树维护当前有哪些半径. 那么将扇形差分,每段 ...
- 矩形面积并-扫描线 线段树 离散化 模板-poj1151 hdu1542
今天刚看到这个模板我是懵逼的,这个线段树既没有建树,也没有查询,只有一个update,而且区间成段更新也没有lazy标记....研究了一下午,我突然我发现我以前根本不懂扫描线,之所以没有lazy标记, ...
- 4418: [Shoi2013]扇形面积并|二分答案|树状数组
为何感觉SHOI的题好水. ..又是一道SB题 从左到右枚举每个区间,遇到一个扇形的左区间就+1.遇到右区间就-1,然后再树状数组上2分答案,还是不会码log的.. SHOI2013似乎另一道题发牌也 ...
- HDU 1255 覆盖的面积 (扫描线 线段树 离散化 矩形面积并)
题目链接 题意:中文题意. 分析:纯手敲,与上一道题目很相似,但是刚开始我以为只是把cnt>=0改成cnt>=2就行了,. 但是后来发现当当前加入的线段的范围之前 还有线段的时候就不行了, ...
- POJ 1151 Atlantis 矩形面积求交/线段树扫描线
Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...
- hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积
题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> ...
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- 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 ...
随机推荐
- Struts2- 设置默认拦截器
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...
- mysql 修改数据库存储地址
默认目录/var/lib/mysql systemctl stop mysqld cp -pr /var/lib/mysql /data/mysql Create a backup of /etc/m ...
- rails中path、url路径解析,routes信息,form_for剖析,link_to示例,路由实例说明
原创,转载请注明http://www.cnblogs.com/juandx/p/3963023.html rails中path.url路径解析,routes信息,form_for剖析,link_to ...
- win7下hadoop编程eclipse的配置
本人hadoop初学,折腾第一个hadoop1.1.2花了好几天,让各位见笑了, WARN NativeCodeLoader:52 - Unable to load native-hadoop lib ...
- 什么是服务端渲染、客户端渲染、SPA、预渲染,看完这一篇就够了
服务端渲染(SSR) 简述: 又称为后端渲染,服务器端在返回html之前,在html特定的区域特定的符号里用数据填充,再给客户端,客户端只负责解析HTML. 鼠标右击点击查看源码时,页 ...
- 利用层的table-row、table-cell属性进行页面布局
利用层的table-row.table-cell属性可以进行等高.宽度自适应页面布局,这是参看了<我所知道的几种display:table-cell的应用>及<基于display:t ...
- 【转】 如何利用C#代码来进行操作AD
要用代码访问 Active Directory域服务,需引用System.DirectoryServices命名空间,该命名空间包含两个组件类,DirectoryEntry和 DirectorySea ...
- CentOS 7拨号上网(ADSL & PPPoE)
步骤概述: 1.搜寻PPPoE相关软件,本人使用的是rp-pppoe yum search pppoe 2.使用yum安装rp-pppoe yum install rp-pppoe -y 3.开始配置 ...
- Why provision Bare Metal
Here are a few use-cases for bare metal (physical server) provisioning in cloud; there are doubtless ...
- u3d调用自己的dll
原文地址:http://blog.sina.com.cn/s/blog_62f7cb730100zhhf.html 首先用vc建立一个dll工程 然后在里面建立一个testunity.h文件.内容如下 ...