【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 ...
随机推荐
- 对设计领域中Tile和Card的理解
前端工程师离不开设计, 谈到设计就要想到大名鼎鼎的material design主题, 而material是以card为经典单元的, card即卡片, 是层次化模型的最小模块, 用于提供扁平化的信息, ...
- iOS边练边学--通知机制和键盘处理
一.通知中心(NSNotificationCenter) 每一个程序都有一个通知中心实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以想通知中心发布通知(NSNotification),描述 ...
- MongoDB · 引擎特性 · MongoDB索引原理
MongoDB · 引擎特性 · MongoDB索引原理数据库内核月报原文链接 http://mysql.taobao.org/monthly/2018/09/06/ 为什么需要索引?当你抱怨Mong ...
- windows安装ruby,DevKit安装rails,svn安装
Ruby on Rails的安装,是从被称为RubyGems的包管理系统开始的.Ruby on Rails是由Ruby处理系统的类库的.被称为“gem”的格式来进行配置的.“gem”形式的类库,通过使 ...
- archdexls主题游戏页面game-play.php有评论时,报错( ! ) Warning: printf(): Too few arguments in D:\wamp\www\wp-content\themes\arcadexls\games-play.php on line 97
( ! ) Warning: printf(): Too few arguments in D:\wamp\www\wp-content\themes\arcadexls\games-play.php ...
- tensorflow学习笔记(10) mnist格式数据转换为TFrecords
本程序 (1)mnist的图片转换成TFrecords格式 (2) 读取TFrecords格式 # coding:utf-8 # 将MNIST输入数据转化为TFRecord的格式 # http://b ...
- e661. 确定图像中是否有透明像素
// This method returns true if the specified image has transparent pixels public static boolean hasA ...
- 测试x264编码器的低延时编码和非延时编码
最近在学x264的编码,经过大量的测试,编码1080P的视频,编码10000帧数据. 在设置为低延时编码的时候: 编码线程0,一帧耗时:7.000000 ms.编码线程0,一帧耗时:8.000000 ...
- hunnu--11547--你的组合数学学得怎样?
你的组合数学学得怎样? Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: ...
- HDF5 文件格式简介
三代测序下机的原始数据不再是fastq格式了,而是换成了hdf5 格式,在做三代数据的分析之前,有必要先搞清楚hdf5 这种文件格式; 官网的链接如下:https://support.hdfgroup ...