bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线【线段树+hash】
bzoj题面什么鬼啊……
题目大意:有一个初始值均为0的数列,n次操作,每次将数列(ai,bi-1)这个区间中的数与ci取max,问n次后元素和
离散化,然后建立线段树,每次修改在区间上打max标记即可
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int N=100005;
int n,g[N],tot,a[N],b[N],c[N],has,h[N];
map<int,int>mp;
struct qwe
{
int l,r,mx;
}t[N<<2];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void build(int ro,int l,int r)
{
t[ro].l=l,t[ro].r=r;
if(l==r)
return;
int mid=(l+r)>>1;
build(ro<<1,l,mid);
build(ro<<1|1,mid+1,r);
}
void pd(int ro)
{
if(t[ro].mx!=0)
{
t[ro<<1].mx=max(t[ro<<1].mx,t[ro].mx);
t[ro<<1|1].mx=max(t[ro<<1|1].mx,t[ro].mx);
}
}
void update(int ro,int l,int r,int v)
{
if(l>r)
return;
if(t[ro].l==l&&t[ro].r==r)
{
t[ro].mx=max(t[ro].mx,v);
return;
}
pd(ro);
int mid=(t[ro].l+t[ro].r)>>1;
if(r<=mid)
update(ro<<1,l,r,v);
else if(l>mid)
update(ro<<1|1,l,r,v);
else
update(ro<<1,l,mid,v),update(ro<<1|1,mid+1,r,v);
}
int ques(int ro,int p)
{
if(t[ro].l==t[ro].r)
return t[ro].mx;
pd(ro);
int mid=(t[ro].l+t[ro].r)>>1;
if(p<=mid)
return ques(ro<<1,p);
else
return ques(ro<<1|1,p);
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
a[i]=read(),b[i]=read(),c[i]=read(),g[++tot]=a[i],g[++tot]=b[i];
sort(g+1,g+1+tot);
for(int i=1;i<=tot;i++)
if(i==1||g[i]!=g[i-1])
mp[g[i]]=++has,h[has]=g[i];
build(1,1,has);
for(int i=1;i<=n;i++)
update(1,mp[a[i]]+1,mp[b[i]],c[i]);
long long ans=0;
for(int i=2;i<=has;i++)
{
int nw=ques(1,i);
ans+=1ll*nw*(h[i]-h[i-1]);
}
printf("%lld\n",ans);
return 0;
}
bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线【线段树+hash】的更多相关文章
- BZOJ 1645: [Usaco2007 Open]City Horizon 城市地平线 扫描线 + 线段树 + 离散化
Code: #include<cstdio> #include<algorithm> #include<string> #define maxn 1030000 # ...
- [BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 线段树
链接 题意:N个矩形块,交求面积并. 题解 显然对于每个 \(x\),只要求出这个 \(x\) 上面最高的矩形的高度,即最大值 将矩形宽度离散化一下,高度从小到大排序,线段树区间set,然后求和即可 ...
- 1645: [Usaco2007 Open]City Horizon 城市地平线
1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 315 Solved: ...
- 【BZOJ】1645: [Usaco2007 Open]City Horizon 城市地平线(线段树+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1645 这题的方法很奇妙啊...一开始我打了一个“离散”后的线段树.............果然爆了. ...
- BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线
BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线 Description N个矩形块,交求面积并. Input * Line 1: A single i ...
- 【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树
[BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to ...
- bzoj1645 [Usaco2007 Open]City Horizon 城市地平线
Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at ...
- 【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- [POJ] 3277 .City Horizon(离散+线段树)
来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_z ...
随机推荐
- 对Kaldi nnet3进行奇异值分解(SVD)以减小模型大小
用处 基于SVD实现模型压缩以适配低功耗平台 根据nnet3bin/nnet3-copy,nnet3-copy或nnet3-am-copy的"--edits-config" ...
- layer弹层content写错导致div复制了一次,导致id失效 $().val() 获取不到dispaly:none div里表单的值
错误之源: $("a.consult").click(function () { lib_consult_html = $('#consult-html').h ...
- 易接SDK ios9以上无法弹出充值界面的一种情况
充值需要用到http请求: 打开info.plist, 在app tansport security setting 这个项 , 加入 NSAllowsArbitraryLoads YES
- 关于测试驱动的开发模式以及实战部分,建议看《Python Web开发测试驱动方法》这本书
关于测试驱动的开发模式以及实战部分,建议看<Python Web开发测试驱动方法>这本书
- Linux Shell常用技巧(八) 系统运行状况
十八. 和系统运行状况相关的Shell命令: 1. Linux的实时监测命令(watch): watch 是一个非常实用的命令,可以帮你实时监测一个命令的运行结果,省得一遍又一遍的手动 ...
- 【ZJOI2017 Round1练习】D7T1 graph(提答)
题意: n<=1000 m<=10000 思路:
- Thinkphp5.0 的Model模型
Thinkphp5.0 的Model模型 新建user模型User.php: <?php namespace app\index\model; use think\Model; class Us ...
- hdu - 1565 方格取数(1) && 1569 方格取数(2) (最大点权独立集)
http://acm.hdu.edu.cn/showproblem.php?pid=1565 两道题只是数据范围不同,都是求的最大点权独立集. 我们可以把下标之和为奇数的分成一个集合,把下标之和为偶数 ...
- java基础标识符,关键字,常量
1关键字1.1关键字的概述Java的关键字对java的编译器有特殊的意义,他们用来表示一种数据类型,或者表示程序的结构等,关键字不能用作变量名.方法名.类名.包名.2标识符2.1什么是标识符就是程序员 ...
- Mysql数据库再度使用
查看数据库端口: show global variables like 'port'; 谨记:每一条sql结束的语句后都要接上分号. 在连接数据库时遇到过这种问题: Fatal error: Call ...