Jack knows that there is a great underground treasury in a secret region. And he has a special device that can be used to detect treasury under the surface of the earth. One day he got outside with the device to ascertain the treasury. He chose many different locations on the surface of the earth near the secret region. And at each spot he used the device to detect treasury and got some data from it representing a region, which may contain treasury below the surface. The data from the device at each spot is six integers x1, y1, z1, x2, y2 and z2 (x1<x2, y1<y2, z1<z2). According to the instruction of the device they represent the range of x, y and z coordinates of the region. That is to say, the x coordinate of the region, which may contain treasury, ranges from x1 to x2. So do y and z coordinates. The origin of the coordinates is a fixed point under the ground.
Jack can’t get the total volume of the treasury because these regions don’t always contain treasury. Through years of experience, he discovers that if a region is detected that may have treasury at more than two different spots, the region really exist treasure. And now Jack only wants to know the minimum volume of the treasury.
Now Jack entrusts the problem to you.

题意:问矩形三次以上覆盖的面积

线段树--扫描线裸题,统计1次、2次、3次含以上的长度。

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxm=;
typedef long long ll; ll st1[maxm<<],st2[maxm<<],st3[maxm<<];
int cov[maxm<<],y[maxm],z[maxm]; struct rect{
int x1,y1,z1,x2,y2,z2;
}r[]; struct seg{
int x,y1,y2,c;
bool operator < (const seg a)const{
return x<a.x;
}
}s[maxm]; void pushup(int o,int l,int r){
if(cov[o]>=)st1[o]=st2[o]=st3[o]=y[r]-y[l];
else if(cov[o]==){
st1[o]=st2[o]=y[r]-y[l];
if(l+==r)st3[o]=;
else st3[o]=st1[o<<]+st1[o<<|];
}
else if(cov[o]==){
st1[o]=y[r]-y[l];
if(l+==r)st2[o]=st3[o]=;
else{
st2[o]=st1[o<<]+st1[o<<|];
st3[o]=st2[o<<]+st2[o<<|];
}
}
else{
if(l+==r)st1[o]=st2[o]=st3[o]=;
else{
st1[o]=st1[o<<]+st1[o<<|];
st2[o]=st2[o<<]+st2[o<<|];
st3[o]=st3[o<<]+st3[o<<|];
}
}
} void update(int o,int l,int r,seg a){
if(a.y1<=y[l]&&a.y2>=y[r]){
cov[o]+=a.c;
pushup(o,l,r);
return;
}
if(l+==r)return;
int m=l+((r-l)>>);
if(a.y1<y[m])update(o<<,l,m,a);
if(a.y2>y[m])update(o<<|,m,r,a);
pushup(o,l,r);
} int main(){
int T;
scanf("%d",&T);
for(int q=;q<=T;++q){
int n;
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d%d%d%d%d%d",&r[i].x1,&r[i].y1,&r[i].z1,&r[i].x2,&r[i].y2,&r[i].z2);
y[*i-]=r[i].y1;
y[*i]=r[i].y2;
z[*i-]=r[i].z1;
z[*i]=r[i].z2;
}
sort(y+,y+*n+);
sort(z+,z+*n+);
int cntz=,cnty=;
ll ans=;
for(int i=;i<=*n;++i){
if(y[i]!=y[i-])y[++cnty]=y[i];
if(z[i]!=z[i-])z[++cntz]=z[i];
}
for(int i=;i<cntz;++i){
int cnt=;
for(int j=;j<=n;++j){
if(r[j].z1<=z[i]&&r[j].z2>z[i]){
++cnt;
s[cnt].x=r[j].x1;s[cnt].y1=r[j].y1;s[cnt].y2=r[j].y2;
s[cnt].c=;
++cnt;
s[cnt].x=r[j].x2;s[cnt].y1=r[j].y1;s[cnt].y2=r[j].y2;
s[cnt].c=-;
}
}
sort(s+,s+cnt+);
ll sum=;
for(int j=;j<cnt;++j){
update(,,cnty,s[j]);
sum+=st3[]*(s[j+].x-s[j].x);
}
update(,,cnty,s[cnt]);
ans+=sum*(z[i+]-z[i]);
}
printf("Case %d: %lld\n",q,ans);
}
return ;
}

hdu3642 Get The Treasury 线段树--扫描线的更多相关文章

  1. HDU 3642 Get The Treasury (线段树扫描线,求体积并)

    参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. POJ1151+线段树+扫描线

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

随机推荐

  1. jquery checkbox的使用

    获取单个checkbox选中的写法: $('input:checkbox:checked').val(); $("input:[type='checkbox']:checked") ...

  2. unity3D 中的C#脚本一个类调用另一类中简单方法

    案例展示 SubMenuManage类中的实例化代码如下: static SubMenuManage sub_this; public static SubMenuManage Instance() ...

  3. sqlalchemy动态组合查询语句。

    if filter_type == 1: search = and_(GameRoom.status ==1,or_( and_(GameRoom.white_user_id == user_id, ...

  4. OPENWRT安装配置指南之 17.01.4 LEDE

    简介 这个东西,需要看简介的就不要看下去了. 下面已刚刷进去,路由IP地址为192.168.1.1为例开始配置. 浏览器访问192.168.1.1,无密码. 一:配置上网 不管你是什么方式上网,请根据 ...

  5. 1043 输出PATest

    给定一个长度不超过 10​4​​ 的.仅由英文字母构成的字符串.请将字符重新调整顺序,按 PATestPATest.... 这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一样多的,若某种 ...

  6. 用servlet实现用户登录案例

    以下实现登录窗口 Login.jsp <!--Login.jsp--> <%@ page language="java" import="java.ut ...

  7. session会话示例

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  8. SharePoint REST API - 基本操作(二)

    博客地址:http://blog.csdn.net/FoxDave 上一节讲了SharePoint REST API的一些基本操作,本节将继续介绍一些关于SharePoint REST API的内容. ...

  9. intellij怎么导入MySQL的驱动包

    1.下载zip格式的驱动包:https://dev.mysql.com/downloads/connector/j/ 2.解压zip,放到任意位置.其中的mysql-connector-java.ja ...

  10. python 时间格式化

    2018-10-25 17:49:51 监控软件 原始 2018-10-2517:49:51 切割后 2018/10/25 17:49:51 格式化后 shijian = ' '.join(respo ...