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 ...
随机推荐
- SpringBoot的第一个例子
1. 安装springboot的开发IDE,IntelliJ IDEA 2016.3.1这个工具,在IDE的官网上可以下载最新版本.https://www.jetbrains.com/idea/#ch ...
- scrollWidth,clientWidth与offsetWidth的区别
scrollWidth 是对象的实际内容的宽,不包边线宽度,会随对象中内容的多少改变(内容多了可能会改变对象的实际宽度). clientWidth 是对象可见的宽度,不包滚动条等边线,会随窗口的显 ...
- Spring中对象和属性的注入方式
一:Spring的bean管理 1.xml方式 bean实例化三种xml方式实现 第一种 使用类的无参数构造创建,首先类中得有无参构造器(重点) 第二种 使用静态工厂创建 (1)创建静态的方法,返回类 ...
- oracle 随机数(转载)
http://blog.sina.com.cn/s/blog_6a01140c0100wimi.html 1.从表中随机取记录 select * from (select * from staff o ...
- Day20 Ajax
Ajax准备知识:json 什么是json? 定义: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w ...
- 得到Android keystore签名的命令方法
keytool -list -v -keystore keyfile.jks 上面这个命令是用来得到一些签名字符串,这些字符串用来在各种平台上填资料的 再来个手动签名的命令: jarsigner -v ...
- 神奇的namespace使用
一大波概念正在来袭: 作用域与命名空间 相关概念 与命名空间相关的概念有: 声明域(declaration region)—— 声明标识符的区域.如在函数外面声明的全局变量,它的声明域为 ...
- activeMq的入门程序
生产者 1.导入相关依赖 2.交给Spring管理,写入相关配置JmsTemplate @RunWith(SpringJUnit4ClassRunner.class) @ContextConfigur ...
- 函数上下文this
一般来说谁调用上下文都指向谁,具体有以下几种情况: 1.函数用圆括号调用,函数的上下文是window 注意:所有的全局变量都是window的属性,而函数里边定义的变量谁的属性也不是. 2.函数作为对象 ...
- 0511JS流程练习
一.输入三个数,判断大小 var one = prompt("请输入第一个数"); var two = prompt("请输入第二个数"); var three ...