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 ...
随机推荐
- Mego(04) - NET简单实现EXCEL导入导出
前言 相信做过信息系统的朋友都会遇到EXCEL导入导出的相关开发,做过不少EXCEL导入导出后总结起来大致有如下几种方式实现: ADO.NET的OldDb或ODBC连接EXCEL使用DataTable ...
- R实战 第七篇:绘图文本表
文本表是显示数据的重要图形,一个文本表按照区域划分为:列标题,行标题,数据区,美学特征有:前景样式.背景央视.字体.网格线等. 一,使用ggtexttable绘图文本表 载入ggpubr包,可以使用g ...
- 如何写jquery插件
首页 新文章 联系 管理 订阅 自己写一个 jQuery 插件 我知道这一天终将会到来,现在,它来了. 需求 开发 SharePoint 的 CSOM 应用时,经常需要在网页上输出一 ...
- servlet什么时候被实例化?【转】
如果没有设置loadOnStartup,则第一次请求的时候实例化 分三种情况:loadOnStartup < 0 即负数的情况下,web容器启动的时候不做实例化处理,servlet首次被调用时做 ...
- python的约束库constraint解决《2018刑侦科题目》
Github地址:https://github.com/ZJW9633/hello-word/blob/master/Xingzhenke 题目分析: 10道题互相关联,耦合性强,暴力求解需4^10种 ...
- 报错:严重: Servlet.service() for servlet [springmvc] in context with path [ ] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
解决:service类或dao类需要@Autowired
- Centos制作本地yum源
本地YUM源制作 1. YUM相关概念 1.1. 什么是YUM YUM(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shel ...
- 条件随机场CRF(二) 前向后向算法评估标记序列概率
条件随机场CRF(一)从随机场到线性链条件随机场 条件随机场CRF(二) 前向后向算法评估标记序列概率 条件随机场CRF(三) 模型学习与维特比算法解码 在条件随机场CRF(一)中我们总结了CRF的模 ...
- ruby klb.rb irb
1.字符串格式化 Python "%s=%s" % (k, v) 在阅读 Python 字符串格式化的时候,视线先看到字符串的 %s 字样,但是不知道这指的是什么,然后看后面的变量 ...
- MySql 物理文件组成
1.日志文件 MySQL 各类日志文件介绍 2.数据文件 MySQL 各类数据文件介绍