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 ...
随机推荐
- html5中的网页结构
一.html5中的大纲 在html5中,使用各种结构元素所描述出来的整个网页的层次结构,就是该网页的大纲.因此在组织这份大纲的时候,不能使用div元素,因为div元素只能当做容器,用在需要对网页中某个 ...
- 将文件内容转化为byte数组返回
如何将文件内容转化为byte数组并返回呢?对于这个问题,我献上我第一次成功的代码~ package com.succez.task1; import java.io.ByteArrayOutputSt ...
- DB2常用命令小结
PS:执行命令前需要进入DB2的账户下:su db2inst1 修改密码:更改相应的操作系统密码即可,windows上可以更改db2admin的密码,linux上更改db2inst1的密码即可,db2 ...
- JAVA堆栈的区别
1. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆. 2. 栈的优势是,存取速度 ...
- 初识Java——日期的格式化
import java.util.*; class DateTest{ static{ System.out.println("谢谢使用!");//代码块,在初始化类时,先执行代码 ...
- myBatis之入门示例
1. myBatis目录结构: --src ---entity [POJO类] ---mappers [映射类] ----*Mapper.java [方法接口,相当于Dao] ----*Mapper. ...
- git push 报错 "Peer certificate cannot be authenticated with known CA certificates"
使用git push -u origin master 命令向远程仓库提交代码时报错:Peer certificate cannot be authenticated with known CA ce ...
- Kali Linux信息收集工具
http://www.freebuf.com/column/150118.html 可能大部分渗透测试者都想成为网络空间的007,而我个人的目标却是成为Q先生! 看过007系列电影的朋友,应该都还记得 ...
- 阿里云服务器连接邮箱SMTP服务器time out的解决
给官方提了个工单,回复如下: 去年9月底开始,出于上级对垃圾邮件管控的要求,新购VPC服务器限制了25端口,我们建议您使用邮件服务商的加密465端口. 或者您查询下所希望访问的发信服务是否提供了像阿里 ...
- windows xp + mysql5.5 + phpmyadmin insert 中文繁體
windows xp + mysql5.5 + phpmyadmin insert 中文繁體 今天也發生了,無法insert成功的問題: 在phpmyadmin 或doc下連接mysql執行都不行: ...