HDU 3255 扫描线(立方体体积并变形)
Farming
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1375 Accepted Submission(s): 402
Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other -- finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins).
There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices.
As a rule, more powerful seeds always grow up into more expensive vegetables.
Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm.
Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
The next line contains m distinct positive integers pi (1 <= pi <= 100), the prices of each kind of vegetable.
The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input.
Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lower-left corner (x1,y1), upper-right corner (x2,y2), with the s-th kind of seed.
All of x1, y1, x2, y2 will be no larger than 106 in their absolute values.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 30005
#define ll root<<1
#define rr root<<1|1
#define mid (a[root].l+a[root].r)/2 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} struct node{
int l, r, val, sum;
}a[N*]; struct Line{
int x1, x2, y, val;
Line(){}
Line(int a,int b,int c,int d){
x1=a;
x2=b;
y=c;
val=d;
}
}line[N*]; bool cmp(Line a,Line b){
return a.y<b.y;
} struct Cube{
int x1, y1, z1, x2, y2, z2;
}cu[N]; int n, m;
int p[];
int xx[N*];
int zz[N*];
int nx, nz; int b_s(int key){
int l=, r=nx-;
while(l<=r){
int mm=(l+r)/;
if(xx[mm]==key) return mm;
else if(xx[mm]>key) r=mm-;
else if(xx[mm]<key) l=mm+;
}
} void build(int l,int r,int root){
a[root].l=l;
a[root].r=r;
a[root].val=a[root].sum=;
if(l==r) return;
build(l,mid,ll);
build(mid+,r,rr);
} void up(int root){
if(a[root].val) a[root].sum=xx[a[root].r+]-xx[a[root].l];
else if(a[root].l==a[root].r) a[root].sum=;
else a[root].sum=a[ll].sum+a[rr].sum;
} void update(int l,int r,int val,int root){
if(a[root].l==l&&a[root].r==r){
a[root].val+=val;
up(root);
return;
}
if(r<=a[ll].r) update(l,r,val,ll);
else if(l>=a[rr].l) update(l,r,val,rr);
else{
update(l,mid,val,ll);
update(mid+,r,val,rr);
}
up(root);
} main()
{
int t, i, j, k;
int kase=;
cin>>t;
while(t--){
scanf("%d %d",&n,&m);
for(i=;i<=m;i++) scanf("%d",&p[i]);
nx=nz=;
for(i=;i<n;i++){
scanf("%d %d %d %d %d",&cu[i].x1,&cu[i].y1,&cu[i].x2,&cu[i].y2,&cu[i].z2);
cu[i].z1=;
cu[i].z2=p[cu[i].z2];
xx[nx++]=cu[i].x1;
xx[nx++]=cu[i].x2;
zz[nz++]=cu[i].z1;
zz[nz++]=cu[i].z2;
}
sort(xx,xx+nx);
sort(zz,zz+nz);
nx=unique(xx,xx+nx)-xx;
nz=unique(zz,zz+nz)-zz;
__int64 ans=;
for(i=;i<nz;i++){
k=;
for(j=;j<n;j++){
if(cu[j].z1<=zz[i-]&&cu[j].z2>=zz[i]){
line[k++]=Line(cu[j].x1,cu[j].x2,cu[j].y1,);
line[k++]=Line(cu[j].x1,cu[j].x2,cu[j].y2,-);
}
}
sort(line,line+k,cmp);
build(,nx,);
__int64 num=;
for(j=;j<k-;j++){
update(b_s(line[j].x1),b_s(line[j].x2)-,line[j].val,);
num+=(__int64)a[].sum*(__int64)(line[j+].y-line[j].y);
}
ans+=num*(__int64)(zz[i]-zz[i-]);
}
printf("Case %d: %I64d\n",kase++,ans);
}
}
HDU 3255 扫描线(立方体体积并变形)的更多相关文章
- hdu 3255 Farming(扫描线)
题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 3642 扫描线(立方体体积并)
Get The Treasury Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3265 扫描线(矩形面积并变形)
Posters Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 3255 体积并
http://www.cnblogs.com/kane0526/archive/2013/03/07/2948446.html http://blog.csdn.net/acdreamers/arti ...
- HDU 3255 Farming (线段树+扫面线,求体积并)
题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...
- HDU 3255 Farming
矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...
- HDU 2002 计算球体积
题目链接:HDU 2002 Description 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每 ...
- hdu 1542 扫描线求矩形面积的并
很久没做线段树了 求矩形面积的并分析:1.矩形比较多,坐标也很大,所以横坐标需要离散化(纵坐标不需要),熟悉离散化后这个步骤不难,所以这里不详细讲解了,不明白的还请百度2.重点:扫描线法:假想有一条扫 ...
随机推荐
- view的封装
如果一个view内部的子控件比较多,一般会考虑自定义一个view,把它内部子控件的创建屏蔽起来,不让外界关心 外界可以传入对应的模型数据给view,view拿到模型数据后给内部的子控件设置对应的数据 ...
- 转:如何学习SQL(第四部分:DBMS扩展功能与SQL高级话题)
转自:http://blog.163.com/mig3719@126/blog/static/285720652010950102575/ 9. DBMS提供的扩展功能 掌握了基本的关系模型原理和DB ...
- Ubuntu 查看文件以及磁盘空间大小管理
(1)查看文件大小 查看当前文件夹下所有文件大小(包括子文件夹) du -sh # du -h15M ./package16K ./.fontconfig4.0K . ...
- Spring MVC 之文件上传(七)
SpringMVC同样使用了apache的文件上传组件.所以需要引入以下包: apache-commons-fileupload.jar apache-commons-io.jar 在springAn ...
- 删除github账号的方法
如果你不想使用自己的github账号了,github官网允许你删除账号,具体操作步骤为: 1.登录github网站,网站右上角的头像,在下拉菜单中选择"Settings"(设置): ...
- nginx的启动与关闭
[root@nginx ~]# #默认启动方式 [root@nginx ~]# which nginx /sbin/nginx [root@nginx ~]# nginx [root@nginx ~] ...
- karma+angular
下面的介绍以karma能正常运行为前提,看karma系列文章:http://www.cnblogs.com/laixiangran/tag/Karma/ 目录结构 步骤 安装 npm install ...
- JavaScript设计模式与开发实践 - 单例模式
引言 本文摘自<JavaScript设计模式与开发实践> 在传统开发工程师眼里,单例就是保证一个类只有一个实例,实现的方法一般是先判断实例存在与否,如果存在直接返回,如果不存在就创建了再返 ...
- js更改input标签的读写属性
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【转】 Live555
Ⅰ live555简介 Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现了对多种音视频编 ...