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张海报,海报 ...
随机推荐
- typedef 各类定义,各类问题大全
第一篇:typedef struct与struct的区别 1. 基本解释 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数据类型(int,char等)和自定 ...
- python代码中使用settings
在具体的Django应用中,通过引入 django.conf.settings 使用配置,例: from django.conf import settings settings.configure( ...
- Python DBUtils
1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DBUtils提供两种外部接口: P ...
- sharepoint部件webparth关闭找回的方法
- Java for LeetCode 139 Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- BFS:Meteor Shower(POJ 3669)
奔跑吧,傻牛 题目大意:这只Bessie的牛又要来闹事了,这次她的任务就是来躲流星雨,流星雨就是在一定时间会从天上砸到Bessie的所在的正方形区域内(Bessie在0,0的位置),然后砸下 ...
- PIGOSS
http://blog.sina.com.cn/s/blog_865bc4c60102wkb1.html
- 深入浅出TCP协议的三次握手过程
TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 每一次TCP连接都需要三个阶段:连接建立.数据传送和连接释放.“三次握手”就发生在连接建立阶段. 1.三次握手( ...
- InputStream的三个read的区别
转自:http://www.blogjava.net/toby/archive/2009/04/24/267413.html 1.read这个方法是对这个流一个一个字节的读,返回的int就是这个字节的 ...
- 使用startActivityForResult方法(转)
功能: A.java 是主界面,B.java 是子功能模块,要从A启动B,B干完活之后把结果汇报给A 注意: 使用startActivityForResult方法 在配置文件就是不能指定Activi ...