POJ 3277 线段树+扫描线
题意:
思路:
线段树求矩形面积的并。。。同 POJ 1151
//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 88888
int n,u,tot,xx,yy,h[N];
long long ans;
struct Node{int x,h,cover;}node[4*N];
struct Tree{int l,r,cover,len;}tree[4*N];
bool cmp(Node a,Node b){return a.x<b.x;}
void build(int l,int r,int pos){
tree[pos].l=h[l],tree[pos].r=h[r];
if(r==l+1)return;
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
build(l,mid,lson),build(mid,r,rson);
}
void push_up(int l,int r,int pos){
if(tree[pos].cover)tree[pos].len=tree[pos].r-tree[pos].l;
else if(l+1==r)tree[pos].len=0;
else tree[pos].len=tree[pos<<1].len+tree[pos<<1|1].len;
}
void insert(int l,int r,int pos,Node jy){
if(tree[pos].r<=jy.h){tree[pos].cover+=jy.cover,push_up(l,r,pos);return;}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(tree[lson].r>=jy.h)insert(l,mid,lson,jy);
else insert(l,mid,lson,jy),insert(mid,r,rson,jy);
push_up(l,r,pos);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&xx,&yy,&h[i]);
node[++tot].x=xx,node[tot].h=h[i],node[tot].cover=1;
node[++tot].x=yy,node[tot].h=h[i],node[tot].cover=-1;
}
sort(node+1,node+1+tot,cmp),sort(h+1,h+1+n);
u=unique(h+1,h+1+n)-h-1;
build(0,u,1),insert(0,u,1,node[1]);
for(int i=2;i<=tot;i++){
ans+=(long long)(node[i].x-node[i-1].x)*tree[1].len;
insert(0,u,1,node[i]);
}
printf("%lld\n",ans);
}
POJ 3277 线段树+扫描线的更多相关文章
- POJ 1151 线段树+扫描线
题意:求矩形面积的并 思路: 注意是[l,mid][mid,r] 这是真正的线段了 就当扫描线模板使吧~ //By SiriusRen #include <cmath> #include ...
- POJ 1151 线段树+扫描线(计算矩形面积并)
前一篇博客有了讲解就不再叙述了 #include<cstdio> #include<cstring> #include<cmath> #include<ios ...
- 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
随机推荐
- 怎样在Web项目中的service业务层获取项目根路劲
这里我们有两个前提 1.没有使用struts2框架.没有使用servlet,无法给service层传递request对象. 2.使用了Spring框架. 那你可能问.会有这样的情况吗?答案是有的,比方 ...
- Testbench的编写
Testbench的作用,在于给我们编写的可综合代码的模块送入激励.即在我们波形仿真中用编写testbench来代替拖拽波形.其中还包括了我们硬件仿真与matlab仿真的联调建立(将matlab产生的 ...
- m_Orchestrate learning system---三、session使用完整流程是什么
m_Orchestrate learning system---三.session使用完整流程是什么 一.总结 一句话总结: 1.在登录成功之后设置session和cookie 2.在公共控制器里面使 ...
- php设计模式之桥接模式
php设计模式之桥接模式 一.概述 桥接模式:将两个原本不相关的类结合在一起,然后利用两个类中的方法和属性,输出一份新的结果. 其实就是讲不相关的东西通过类(本例中是SendInfo)结合在一起,从而 ...
- nyoj--1087--摆方格(规律)
摆方格 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给你一个n*n的方格,每个方格里的数必须连续摆放如 1 2 4 3 ,下图为不连续的,请输出从左上角到右下角的对角 ...
- ora-01157怎么解决
在数据库startup时,出现以下两个错误:ora-01157:cannot identify/lock data file 8 -see DBWR trace fileora-01110:data ...
- 关于linux下QIODevice类进行读取的几个方法的理解
Qt中对读写设备的支持力度很大,其都继承与QIODevice类,其中有几个方法是非常值得注意的,不管是在用原始的serial port进行通信还是使用网络的TCP/IP 或者UDP或者HTTP等协议时 ...
- Django(part2)
admin site:django自带了admin site,我们需要创建能访问site的用户 #以交互的方式创建超级用户 manage.py createsuperuser 如果要把model加到a ...
- HttpWebRequest WebExcepton: The remote server returned an error: (407) Proxy Authentication Required.
1. Supply the credentials of the Currently Logged on User to the Proxy object similar to this: // Be ...
- 8年js总结
http://www.cnblogs.com/tylerdonet/p/5543813.html