BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树
BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树
题意:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 90050
#define LL long long
#define ls p<<1
#define rs p<<1|1
int n,S,T;
LL f[N],t[N<<2],tag[N<<2];
struct A
{
int s,t,v;
}a[10050];
bool cmp(const A &x,const A &y)
{
if(x.s==y.s)return x.t<y.t;
return x.s<y.s;
}
void pud(int p)
{
if(tag[p]==-1)return ;
t[ls]=min(t[ls],tag[p]);
if(tag[ls]!=-1)tag[ls]=min(tag[ls],tag[p]);
else tag[ls]=tag[p];
t[rs]=min(t[rs],tag[p]);
if(tag[rs]!=-1)tag[rs]=min(tag[rs],tag[p]);
else tag[rs]=tag[p];
tag[p]=-1;
}
void update(int l,int r,int x,int y,LL c,int p)
{
if(x<=l&&y>=r)
{
t[p]=min(t[p],c);
if(tag[p]!=-1)tag[p]=min(tag[p],c);
else tag[p]=c;
return ;
}
pud(p);
int mid=l+r>>1;
if(x<=mid)update(l,mid,x,y,c,ls);
if(y>mid)update(mid+1,r,x,y,c,rs);
t[p]=min(t[ls],t[rs]);
}
LL query(int l,int r,int x,int y,int p)
{
if(x<=l&&y>=r)return t[p];
pud(p);
LL re=1ll<<60;
int mid=l+r>>1;
if(x<=mid)re=min(re,query(l,mid,x,y,ls));
if(y>mid)re=min(re,query(mid+1,r,x,y,rs));
t[p]=min(t[ls],t[rs]);
return re;
}
int main()
{
scanf("%d%d%d",&n,&S,&T);
memset(tag,-1,sizeof(tag));
memset(t,0x3f,sizeof(t));
int i,x,y,v;
update(S-1,T,S-1,S-1,0,1);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i].s,&a[i].t,&a[i].v);
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=n;i++)
{
LL tmp=query(S-1,T,a[i].s-1,a[i].t,1)+a[i].v;
update(S-1,T,a[i].s-1,a[i].t,tmp,1);
}
LL tmp=query(S-1,T,T,T,1);
if(tmp>1ll*86400ll*500000ll)printf("-1\n");
else printf("%lld\n",tmp);
}
BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树的更多相关文章
- [Usaco2005 Dec]Cleaning Shifts 清理牛棚 (DP优化/线段树)
[Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new ...
- 【BZOJ】1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(dp/线段树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1672 dp很好想,但是是n^2的..但是可以水过..(5s啊..) 按左端点排序后 f[i]表示取第 ...
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚【dp+线段树】
设f[i]为i时刻最小花费 把牛按l升序排列,每头牛能用f[l[i]-1]+c[i]更新(l[i],r[i])的区间min,所以用线段树维护f,用排完序的每头牛来更新,最后查询E点即可 #includ ...
- BZOJ1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 414 Solved: ...
- BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MB Description Farm ...
- P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚
P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可 ...
- 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划
[BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...
- 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...
- 洛谷P4644 [USACO2005 Dec]Cleaning Shifts 清理牛棚 [DP,数据结构优化]
题目传送门 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness ...
随机推荐
- Xshell 链接 Could not connect to '192.168.80.129' (port 22): Connection failed
在使用Xshell链接虚拟机VM里面的Linux的时候.链接失败,报 Could not connect to ): Connection failed 解决步骤: 1.重启VM.Linux.Xshe ...
- 基础概念:Oracle数据库、实例、用户、表空间、表之间的关系
基础概念:Oracle数据库.实例.用户.表空间.表之间的关系 数据库: Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库 ...
- java垃圾回收总结(2)
java垃圾回收总结(2) 上一篇文章 介绍了jvm虚拟机运行时内存结构以及如何标识需要回收的对象,这一节主要讲解垃圾回收的基本算法. 基本上 jvm内存回收有三种 基本算法 标记-清除 标记清除 ...
- [ SSH框架 ] Hibernate框架学习之四(JPA)
一.JPA概述以及它和Hibernate之间的关系 1.1.Hibernate 概述 JPA Java Persistence API,是EJB3规范中负责对象持久化的应用程序编程接口(ORM接口), ...
- WSL与Windows交互实践
1. WSL是什么 2. WSL新特性 3. WSL管理配置 4. WSL交互 5. 解决方案 * 5.1 使用别名 * 5.2 多复制一份 * 5.3 重定向 * 5.4 symlink 6 ...
- SpringCloud实战-Eureka
熟悉微服务架构或Dubbo框架的都知道,微服务中最核心.最基础的组件就是注册中心了.下面利用Spring Cloud Eureka实现服务注册中心.并注册一个简单的服务提供者. 首先先创建一个spir ...
- Myeclipse使用git
推荐使用服务器:coding,coding的上传很稳定很快 怎么建仓库: coding 这个服务器呢有个很明显的东西就是太的语言可以是中文的, 点头标签的加号就能进行创建仓库了 点击新建就行了 点击这 ...
- jvm GC
JavaGC.新生代.老年代 Java 中的堆是 JVM所管理的最大的一块内存空间,主要用于存放各种类的实例对象. 在 Java 中,堆被划分成两个不同的区域:新生代 ( Young ).老年代 ( ...
- python奇技淫巧——max/min函数的用法
本文以max()为例,对min/max内建函数进行说明 源码 def max(*args, key=None): # known special case of max ""&qu ...
- Mysql连接问题:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establish ...