设f[i]为i时刻最小花费

把牛按l升序排列,每头牛能用f[l[i]-1]+c[i]更新(l[i],r[i])的区间min,所以用线段树维护f,用排完序的每头牛来更新,最后查询E点即可

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=10005;
const long long inf=1e18;
int n,st,ed;
struct xds
{
int l,r;
long long lz,mn;
}t[2000005];
struct qwe
{
int l,r,v;
}a[N],s[N];
bool cmp(const qwe &a,const qwe &b)
{
return a.l<b.l;
}
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 pd(int ro)
{
if(t[ro].lz!=inf)
{
t[ro<<1].mn=min(t[ro<<1].mn,t[ro].lz);
t[ro<<1].lz=min(t[ro<<1].lz,t[ro].lz);
t[ro<<1|1].mn=min(t[ro<<1|1].mn,t[ro].lz);
t[ro<<1|1].lz=min(t[ro<<1|1].lz,t[ro].lz);
t[ro].lz=inf;
}
}
void build(int ro,int l,int r)
{
t[ro].l=l,t[ro].r=r,t[ro].mn=t[ro].lz=inf;
if(l==r)
return;
int mid=(l+r)>>1;
build(ro<<1,l,mid);
build(ro<<1|1,mid+1,r);
}
long long ques(int ro,int p)
{
if(p<st)
return 0;
if(t[ro].l==t[ro].r)
return t[ro].mn;
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);
}
void update(int ro,int l,int r,long long v)
{
if(t[ro].l==l&&t[ro].r==r)
{
t[ro].mn=min(t[ro].mn,v);
t[ro].lz=min(t[ro].lz,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);
t[ro].mn=min(t[ro<<1].mn,t[ro<<1|1].mn);
}
int main()
{
n=read(),st=read(),ed=read();
for(int i=1;i<=n;i++)
a[i].l=read(),a[i].r=read(),a[i].v=read();
sort(a+1,a+1+n,cmp);
build(1,st,ed);
for(int i=1;i<=n;i++)
{
long long nw=ques(1,a[i].l-1);
if(nw==inf)
{
puts("-1");
return 0;
}
update(1,a[i].l,a[i].r,a[i].v+nw);
}
long long ans=ques(1,ed);
printf("%lld\n",ans==inf?-1ll:ans);
return 0;
}
/*
3 0 4
0 2 3
3 4 2
0 0 1
*/

bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚【dp+线段树】的更多相关文章

  1. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚 dp/线段树

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

  2. BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farm ...

  3. [Usaco2005 Dec]Cleaning Shifts 清理牛棚 (DP优化/线段树)

    [Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new ...

  4. 【BZOJ】1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(dp/线段树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1672 dp很好想,但是是n^2的..但是可以水过..(5s啊..) 按左端点排序后 f[i]表示取第 ...

  5. 洛谷P4644 [USACO2005 Dec]Cleaning Shifts 清理牛棚 [DP,数据结构优化]

    题目传送门 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness ...

  6. BZOJ1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 414  Solved: ...

  7. BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树

    BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树 题意:  约翰的奶牛们从小娇生惯养,她们无法容忍牛棚里的任何脏东西.约翰发现,如果要使这群 ...

  8. P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可 ...

  9. 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划

    [BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...

随机推荐

  1. JQuery Easy UI 简介

    [什么是JQuery Easy UI?] jQuery EasyUI 是一组基于 jQuery 的 UI 插件集合,而 jQuery EasyUI 的目标就是帮助Web 开发者更轻松的打造出功能丰富并 ...

  2. swift -从相册中选择照片并上传

    选择本地图片并上传是应用开发中一个比较常见的功能.        原文出自:www.hangge.com  转载请保留原文链接:http://www.hangge.com/blog/cache/det ...

  3. 全文搜索(AC-1)-互联网信息过载问题

    什么是信息过载? 信息检索技术是什么? 信息过滤技术是什么?

  4. Java 学习(5):修饰符 运算符

    目录 --- 修饰符 --- 运算符 --- 循环结构 --- 分支结构 修饰符: 修饰符用来定义类.方法或者变量,通常放在语句的最前端.如下: public class className { // ...

  5. Visual C++ 网络编程 笔记

    第一章 网络分层模型 OSI模型应用层:服务于应用程序的协议,比如用于域名解析的DNS协议,用于下载界面内容的HTTP协议表示层:处理不同硬件和操作系统之间的差异,确保应用层之间顺利通信 and 加密 ...

  6. 博弈论入门题 kiki's game

    Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind ...

  7. abs 暴力

    Given a number x, ask positive integer y≥2y≥2, that satisfy the following conditions: 1. The absolut ...

  8. 蓝桥杯 地宫寻宝 带缓存的DFS

      历届试题 地宫取宝   时间限制:1.0s   内存限制:256.0MB      问题描写叙述 X 国王有一个地宫宝库. 是 n x m 个格子的矩阵. 每一个格子放一件宝贝. 每一个宝贝贴着价 ...

  9. webpy学习笔记之中的一个

    这几天在学习webpy框架,之前学过一段时间,后来各种转移框架,导致没有学透彻,都是皮毛,各种打印hello world! 汗! 如今将webpy的学习过程和思路写下来,便于复习和总结. 资料主要是w ...

  10. 双层for 循环

    说说 图片 集合 list(set([ii for i in img_url_l for ii in i[0].replace('[','').replace(']','').replace(&quo ...