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. Android 音视频深入 二 AudioTrack播放pcm(附源码下载)

    本篇项目地址,名字是录音和播放PCM,求starhttps://github.com/979451341/Audio-and-video-learning-materials 1.AudioTrack ...

  2. capjoint一些生成文件的解释

    王亮 // :: https://github.com/wangliang1989/oh-my-cap/blob/dev/docs/result.md 这是cap_plt.pl的输入文件.out的各项 ...

  3. 第四周四则运算3 PSP表格

    PSP2.1 Personal Software Process Stages time Plan 计划   -Estimate 整数四则运算 分数四则运算 括号 括号四则运算 在主函数中调用 30m ...

  4. 高级数据类型--列表[list]

    List(列表) 是 Python 中使用 最频繁 的数据类型,在其他语言中通常叫做 数组,专门用于存储 一串 信息,列表用 [] 定义,数据 之间使用 , 分隔,列表的 索引 从 0 开始. nam ...

  5. Oracle备份归档日志文件的两种方法比较

    备份归档日志方式有两种:  1 单独备份归档日志:backup archivelog all  2 在执行备库时一起备份归档日志:backup database plus archivelog;  这 ...

  6. C#窗体的浮动及隐藏

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  7. scrapy面试一

    1.动态加载又对及时性要求很高怎么处理? Selenium+Phantomjs 尽量不使用 sleep 而使用 WebDriverWait 2.分布式爬虫主要解决什么问题? (1)ip (2)带宽 ( ...

  8. wsgi&nginx-理解

    WSGI协议 首先弄清下面几个概念:WSGI:全称是Web Server Gateway Interface,WSGI不是服务器,python模块,框架,API或者任何软件,只是一种规范,描述web ...

  9. python-django优缺点

    [Django]是利用[Python]语言从事[Web]开发的首选框架.如果你以后想从事[python web]开发工作,就必需了解其优缺点.这些都可能会是你将来的面试题哦. [Django]的优点 ...

  10. Dubbo浅谈

    一.高并发的解决 1.高并发:很多人同时访问. 2.高并发产生的性能瓶颈: tomcat支持的controller,解决办法:多个tomcat共同支撑.(tomcat集群) 只有一个service被调 ...