题意:

      给你n个矩形,每个矩形上都有一个权值(该矩形单位面积的价值),矩形之间可能重叠,重叠部分的权值按照最大的算,最后问这n个矩形组成的图形的最大价值。

思路:

      线段树扫描线求长方体体积,对于求体积,如果理解求面积的过程,求体积也很容易理解,就是先一层一层的求面积,然后把面积当成"当前所覆盖的线段",以长方体的高的方向更新,不是很容易说清楚,看下代码就懂了,就体积的时候就是先求出一层面积,然后在用一层一层的面积更新体积,具体看代码吧,应该很容易理解,说着感觉很费劲。


#include<stdio.h>
#include<string.h>
#include<algorithm> #define N 65000
#define Nmax 300000
#define lson l ,mid ,t << 1
#define rson mid ,r ,t << 1 | 1

using namespace
std; typedef struct
{
__int64
l ,r ,h ,mk;
}
EDGE; typedef struct
{
__int64
x1 ,x2 ,y1 ,y2;
__int64
pri;
}
NODE; EDGE edge[N];
NODE node[33000];
__int64
len[Nmax] ,cnt[Nmax];
__int64
tmp[Nmax] ,num[Nmax];
__int64
price[5]; bool camp(EDGE a ,EDGE b)
{
return
a.h < b.h;
} int
search(int id ,__int64 now)
{
int
low ,up ,mid ,Ans;
low = 1 ,up = id;
while(
low <= up)
{

mid = (low + up) >> 1;
if(
now <= num[mid])
{

Ans = mid;
up = mid - 1;
}
else
low = mid + 1;
}
return
Ans;
} void
Pushup(__int64 l ,__int64 r ,__int64 t)
{
if(
cnt[t]) len[t] = num[r] - num[l];
else if(
l + 1 == r) len[t] = 0;
else
len[t] = len[t<<1] + len[t<<1|1];
} void
Update(__int64 l ,__int64 r ,__int64 t ,__int64 a ,__int64 b ,__int64 c)
{
if(
l == a && r == b)
{

cnt[t] += c;
Pushup(l ,r ,t);
return ;
}
__int64
mid = (l + r) >> 1;
if(
b <= mid) Update(lson ,a ,b ,c);
else if(
a >= mid) Update(rson ,a ,b ,c);
else
{

Update(lson ,a ,mid ,c);
Update(rson ,mid ,b ,c);
}

Pushup(l ,r ,t);
} __int64
solve(int n ,int m)
{
__int64
Ans = 0 ,i ,id;
sort(price + 1 ,price + m + 1);
price[0] = 0;
for(int
ii = 1 ;ii <= m ;ii ++)
{
int
nn = 0;
for(
id = 0 ,i = 1 ;i <= n ;i ++)
{
if(
node[i].pri < price[ii]) continue;
nn += 2;
edge[++id].l = node[i].x1;
edge[id].r = node[i].x2 ,edge[id].h = node[i].y1 ,edge[id].mk = 1;
tmp[id] = node[i].x1; edge[++id].l = node[i].x1;
edge[id].r = node[i].x2 ,edge[id].h = node[i].y2 ,edge[id].mk = -1;
tmp[id] = node[i].x2;
}

sort(tmp + 1 ,tmp + id + 1);
id = 0;
for(
i = 1 ;i <= nn ;i ++)
if(
i == 1 || tmp[i] != tmp[i-1])
num[++id] = tmp[i]; sort(edge + 1 ,edge + nn + 1 ,camp);
memset(len ,0 ,sizeof(len));
memset(cnt ,0 ,sizeof(cnt));
__int64
ans = 0;
edge[0].h = edge[1].h;
for(
i = 1 ;i <= nn ;i ++)
{

ans += len[1] * (edge[i].h - edge[i-1].h);
__int64
ll = search(id ,edge[i].l);
__int64
rr = search(id ,edge[i].r);
Update(1 ,nn ,1 ,ll ,rr ,edge[i].mk);
}

Ans += ans * (price[ii] - price[ii-1]);
}
return
Ans;
} int main ()
{
int
t ,n ,m ,cas = 1;
scanf("%d" ,&t);
while(
t--)
{

scanf("%d %d" ,&n ,&m);
for(int
i = 1 ;i <= m ;i ++)
scanf("%I64d" ,&price[i]);
for(int
i = 1 ;i <= n ;i ++)
{

scanf("%I64d %I64d %I64d %I64d %I64d" ,&node[i].x1 ,&node[i].y2 ,&node[i].x2 ,&node[i].y1 ,&node[i].pri);
node[i].pri = price[node[i].pri];
}

printf("Case %d: %I64d\n" ,cas ++ ,solve(n ,m));
}
return
0;
}

hdu3255 线段树扫描线求体积的更多相关文章

  1. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  2. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  3. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  4. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  5. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

  6. BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞

    看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...

  7. hdu 5091(线段树+扫描线)

    上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...

  8. POJ1151+线段树+扫描线

    /* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  9. POJ-1151-Atlantis(线段树+扫描线+离散化)[矩形面积并]

    题意:求矩形面积并 分析:使用线段树+扫描线...因为坐标是浮点数的,因此还需要离散化! 把矩形分成两条边,上边和下边,对横轴建树,然后从下到上扫描上去,用col表示该区间有多少个下边,sum代表该区 ...

随机推荐

  1. POJ-3026(图上的最小生成树+prim算法+gets函数使用)

    Borg Maze POJ-3026 一开始看到这题是没有思路的,看了题解才知道和最小生成树有关系. 题目的意思是每次走到一个A或者S就可以分为多个部分继续进行搜索.这里就可以看出是从该点分出去的不同 ...

  2. POJ-2752(KMP算法+前缀数组的应用)

    Seek the Name, Seek the Fame POJ-2752 本题使用的算法还是KMP 最主要的片段就是前缀数组pi的理解,这里要求解的纸盒pi[n-1]有关,但是还是需要使用一个循环来 ...

  3. 链表算法题之中等级别,debug调试更简单

    文章简述 大家好,本篇是个人的第 5 篇文章 从本篇文章开始,分享关于链表的题目为中等难度,本次共有 3 道题目. 一,两数相加 1.1 题目分析 题中写到数字是按照逆序的方式存储,从进位的角度看,两 ...

  4. pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法

    pygame模块使用时出现AttributeError: module 'pygame' has no attribute '-'错误解决方法 首先在pygame中存在init()模块,出现这样的问题 ...

  5. JDBC 连接池 & Template

    数据库连接池 # 概念:其实就是一个容器(集合),存放数据库连接的容器. * 当系统初始化号以后,容器被创建,容器中会申请一些连接对象,当用户来访问数据库时,从容其中获取连接对象,用户访问完之后,会将 ...

  6. 【odoo14】第六章、管理模块数据

    本章代码可在原作者github下载 使用外部ID及命名空间 外部ID及XML ID用于标记记录.到目前为止,我们在视图.菜单及动作中接触了XML IDs.本节我们将进一步了解什么是XML ID. 步骤 ...

  7. IaaS, PaaS和SaaS的区别

    从小型企业到全球企业,云都是一个非常热门的话题,它是一个非常广泛的概念,涵盖了很多在线领域. 无论是应用程序还是基础架构部署,当您开始考虑将业务转移到云时,了解各种云服务的差异和优势比以往任何时候都更 ...

  8. 服务器安装部署-01-MySQL

    1 MySQL 1.1 安装 在root用户权限下 # 创建mysql用户和用户组,同时禁止登陆 shell> groupadd mysql shell> useradd -r -g my ...

  9. CDN域名解析问题

    CDN域名解析问题 之前配置CDN域名解析,碰到一个配置带www的域名和不带www的域名,这里就有个解析的坑,已经将cdn域名都配置好的,但是一直访问不了,白屏现象 后面排除源站问题和cdn配置问题, ...

  10. 如何快速编写一个微信Api?

    概述 Magicodes.Wx.Sdk致力于打造最简洁最易于使用的微信Sdk,逐步包括公众号Sdk.小程序Sdk.企业微信Sdk等,以及Abp VNext集成. 本篇将侧重于讲述如何向Magicode ...