POJ 3277 City Horizon(扫描线+线段树)
类似求面积并。。2Y。。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL __int64
#define maxn 40100
#define lson l , m, rt<<1
#define rson m+1, r,rt<<1|1
int que[maxn*];
int sum[maxn*];
int cnt[maxn*];
struct node
{
int x,y,s;
node(){}
node(int a,int b,int c):x(a),y(b),s(c){}
bool operator < (const node &S)const
{
return x < S.x;
}
}mat[maxn*];
int bin(int x,int n)
{
int str,mid,end;
str = ;
end = n;
while(str <= end)
{
mid = (str+end)/;
if(que[mid] == x)
return mid;
else if(que[mid] > x)
end = mid - ;
else
str = mid + ;
}
return mid;
}
void pushup(int rt,int l,int r)
{
if(cnt[rt])
{
sum[rt] = que[r+] - que[l];
}
else if(l == r)
sum[rt] = ;
else
sum[rt] = sum[rt<<] + sum[rt<<|];
}
void update(int L,int R,int c,int l,int r,int rt)
{
int m;
if(l >= L&&r <= R)
{
cnt[rt] += c;
pushup(rt,l,r);
return ;
}
m = (l+r)>>;
if(L <= m) update(L,R,c,lson);
if(R > m) update(L,R,c,rson);
pushup(rt,l,r);
}
int main()
{
int n,a,b,c,i,k,num,l,r;
while(scanf("%d",&n)!=EOF)
{
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
num = ;
for(i = ;i < n;i ++)
{
scanf("%d%d%d",&a,&b,&c);
que[num] = ;
mat[num++] = node(a,c,);
que[num] = c;
mat[num++] = node(b,c,-);
}
sort(mat,mat+num);
sort(que,que+num);
k = ;
for(i = ;i < num;i ++)
{
if(que[k] != que[i])
que[k++] = que[i];
}
LL ans = ;
for(i = ;i < num-;i ++)
{
l = ;
r = bin(mat[i].y,k-)-;
if(l <= r)
update(l,r,mat[i].s,,k-,);
ans = ans + (LL)sum[]*(mat[i+].x - mat[i].x);
}
printf("%I64d\n",ans);
}
return ;
}
POJ 3277 City Horizon(扫描线+线段树)的更多相关文章
- 离散化+线段树 POJ 3277 City Horizon
POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...
- 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 ...
- poj 3277 City Horizon (线段树 扫描线 矩形面积并)
题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ...
- [POJ] 3277 .City Horizon(离散+线段树)
来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_z ...
- POJ 3277 City Horizon(叶子节点为[a,a+1)的线段树+离散化)
网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archiv ...
- POJ 3277 City Horizon
标题效果: 每间房子的长度给出阴影(在间隔代表)而高度,求阴影总面积. 解题思路:矩形面积并. 以下是代码: #include <set> #include <map> #in ...
- 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上的一次游览中,你碰到了一个埃及古墓. 不幸的是,你打开了 ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
随机推荐
- 简单制作 OS X Yosemite 10.10 正式版U盘USB启动安装盘方法教程
转自: http://www.iplaysoft.com/osx-yosemite-usb-install-drive.html http://jingyan.baidu.com/article/02 ...
- 【Python】Django Model 怎么使用 UUID 作为主键?
>>> import uuidprint uuid.uuid3(uuid.uuid1(), 'python.org') >>> # make a UUID base ...
- Windows命令行重命名文件
RENAME D:\Cache\xyz.html xyz%date:~0,4%%date:~5,2%%date:~8,2%.tar.gz
- iterator与const_iterator及const iterator区别
如果你传递过来一个const类型的容器,那么只能用const_iterator来遍历. C++ Code 12345 void Method(const vector<int> v ...
- 13.第一个只出现一次的字符[FindFirstNotRepeatingChar]
[题目] 在一个字符串中找到第一个只出现一次的字符.如输入abaccdeff,则输出b. [分析] 这道题是2006年google的一道笔试题. 看到这道题时,最直观的想法是从头开始扫描这个字符串中的 ...
- Python多线程(2)——线程同步机制
本文介绍Python中的线程同步对象,主要涉及 thread 和 threading 模块. threading 模块提供的线程同步原语包括:Lock.RLock.Condition.Event.Se ...
- 【python】format函数格式化字符串的用法
来源:http://www.jb51.net/article/63672.htm 自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式 ...
- HDU2018递推牛
母牛的故事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- github优秀开源项目大全-iOS
github优秀开源项目大全-iOS APR 25TH, 2014 前言 本文旨在搜集github上优秀的开源项目 本文搜集的项目都是用于iOS开发 本文会持续更新… 完整客户端 ioctocat g ...
- Timer&TimerTask原理分析
转载地址,请珍惜作者的劳动成果,转载请注明出处:http://www.open-open.com/lib/view/open1337176725619.html 如果你使用Java语言进行开发,对于定 ...