题目链接

类似求面积并。。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(扫描线+线段树)的更多相关文章

  1. 离散化+线段树 POJ 3277 City Horizon

    POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...

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

  3. poj 3277 City Horizon (线段树 扫描线 矩形面积并)

    题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ...

  4. [POJ] 3277 .City Horizon(离散+线段树)

    来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_z ...

  5. POJ 3277 City Horizon(叶子节点为[a,a+1)的线段树+离散化)

    网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archiv ...

  6. POJ 3277 City Horizon

    标题效果: 每间房子的长度给出阴影(在间隔代表)而高度,求阴影总面积. 解题思路:矩形面积并. 以下是代码: #include <set> #include <map> #in ...

  7. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

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

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

  9. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

随机推荐

  1. 使用MegaCli和Smartctl获取普通磁盘

    设备名称: [root@DB232 shell]# cat /proc/scsi/scsi Attached devices:Host: scsi0 Channel: 02 Id: 00 Lun: 0 ...

  2. AtomicInteger源码分析——基于CAS的乐观锁实现

    AtomicInteger源码分析——基于CAS的乐观锁实现 1. 悲观锁与乐观锁 我们都知道,cpu是时分复用的,也就是把cpu的时间片,分配给不同的thread/process轮流执行,时间片与时 ...

  3. Linux运维

    概要:http://os.51cto.com/art/201312/423616.htm 论坛: http://www.linux360.cn/ https://www.centos.bz/ http ...

  4. iOS 关于Layer的疑问

    很久很久以前,就对ios的Layer十分的不解,学习了android后,打算通过android中的相关实现,分析一下ios中layer的作用,结果没有找到android中的对应的内容!十分让人郁闷.于 ...

  5. Java与数据库类型对照表

     数据库类型  Java类型  INTEGER  int or java.lang.Integer  BIGINT  long or java.lang.Long  SMALLINT  short o ...

  6. MFC添加鼠标相应事件

    Class View (类视图)窗口中选中 你要添加事件的类(比如C***View.CPP),切换到properties窗口. 点击上面的Message图标(在Event图标[一个闪电形状的图标] 右 ...

  7. 深入C++中构造函数、拷贝构造函数、赋值操作符、析构函数的调用过程总结

    转自 http://www.jb51.net/article/37527.htm,感谢作者 #include "stdafx.h"      #include <iostre ...

  8. kvm NET 和 BRIDGE

    net: <interface type='network'> <mac address='52:54:00:e1:ac:43'/> <source network='d ...

  9. 干货分享:IBM StorwizeV7000部署与运维

    http://storage.it168.com/a2014/1211/1689/000001689526_3.shtml

  10. php 解决和避免form表单重复提交的方法

    在提交表单的时候,可能遇到网速等导致页面突然加载变慢,用户重复地点击提交按钮,将在数据库产生多条数据,导致不可控情况. 比如下面的情况就会导致表单重复提交: 点击提交按钮两次. 点击刷新按钮. 使用浏 ...