传送门

显然可以考虑 $dp$

设 $f[i]$ 表示当前到了时间 $i$,从初始到 $i$ 的时间都安排好打扫了

把所有牛按照区间 $l,r$ 双关键字排序

这样枚举到一头牛 $x$ 时,在 $x.l$ 之前的牛都考虑完了($x.l$ 是牛 $x$ 的左区间)

然后枚举 $[x.l-1,x.r]$ 之间的时间 $y$,有转移 $f[x.r]=min(f[x.r],f[y]+x.c)$ ($x.r$ 是牛 $x$ 的右区间,$x.c$ 是牛$x$ 的花费)

这样转移才能保证从开始时间一直到 $x.r$ 都有牛打扫

$x.l-1$ 是因为每头牛打扫的时间是闭区间,$[a,b]+[b+1,c]$ 的方案是合法的

然后这个东西的转移直接用线段树区间求 $min$ 和单点取 $min$ 就行了

具体看代码吧,注意区间可能为 $0$,写线段树的时候区间下标统一加一就行

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e5+;
int n,S,E;
ll T[N<<],tag[N<<];
inline void pushdown(int o,int l,int r)
{
if(!o||tag[o]==T[]) return;
T[o]=min(T[o],tag[o]);
if(l==r) { tag[o]=T[]; return; }
tag[o<<]=min(tag[o<<],tag[o]);
tag[o<<|]=min(tag[o<<|],tag[o]);
tag[o]=T[];
}
int ql,qr;
ll K,res;
inline void change(int o,int l,int r)
{
pushdown(o,l,r);
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { tag[o]=K; pushdown(o,l,r); return; }
int mid=l+r>>;
change(o<<,l,mid); change(o<<|,mid+,r);
T[o]=min(T[o<<],T[o<<|]);
}
inline void query(int o,int l,int r)
{
pushdown(o,l,r);
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { res=min(res,T[o]); pushdown(o,l,r); return; }
int mid=l+r>>;
query(o<<,l,mid); query(o<<|,mid+,r);
T[o]=min(T[o<<],T[o<<|]);
}
struct dat{
int l,r,c;
inline bool operator < (const dat &tmp) const { return l<tmp.l; }
}d[N];
int main()
{
memset(T,0x3f,sizeof(T));
memset(tag,0x3f,sizeof(tag));
n=read(),S=read()+,E=read()+;
for(int i=,a,b,c;i<=n;i++)
{
a=read()+,b=read()+,c=read();
d[i]=(dat){a,b,c};
}
sort(d+,d+n+);
ql=d[].r,qr=d[].r,K=d[].c; change(,,E);
for(int i=;i<=n;i++)
{
res=T[]; ql=max(S,d[i].l-); qr=d[i].r; query(,,E);
if(res==T[]) continue;
K=res+d[i].c; ql=d[i].r; qr=d[i].r; change(,,E);
}
res=T[]; ql=qr=E; query(,,E);
if(res==T[]) printf("-1\n");
else printf("%lld\n",res);
return ;
}

BZOJ1672 Cleaning Shifts 清理牛棚的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚

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

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

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

随机推荐

  1. openstack stein部署手册 8. neutron-api

    # 建立数据库用户及权限 create database neutron; grant all privileges on neutron.* to neutron@'localhost' ident ...

  2. CentOS6.5系统解决中文乱码问题

      一.    问题详情 Windows的默认编码为GBK,Linux的默认编码为UTF-8.在Windows下编辑的中文,在Linux下显示为乱码.为了解决此问题,修改Linux的默认编码为GBK. ...

  3. How to compile and install Linux Kernel 5.1.2 from source code

    How to compile and install Linux Kernel 5.1.2 from source code Compiling a custom kernel has its adv ...

  4. css3-css3属性选择器

    在HTML中,通过各种各样的属性可以给元素增加很多附加的信息.例如,通过id属性可以将不同div元素进行区分. 在CSS2中引入了一些属性选择器,而CSS3在CSS2的基础上对属性选择器进行了扩展,新 ...

  5. hashlib模块subprocess模块

    '''通过一种算法,将字符串得出一种编码内容相同则hash运算结果相同,内容稍微改变则hash值改变不可逆推相同算法,无论校验多长的数据,得到的hash值长度固定'''# import hashlib ...

  6. VUE的双向绑定及局部组件的使用

    vue的双向绑定,使用v-model,v-model只能使用在input  textare    select中 <!DOCTYPE html> <html lang="z ...

  7. C#基础提升系列——C#任务和并行编程

    C#任务和并行编程 我们在处理有些需要等待的操作时,例如,文件读取.数据库或网络访问等,这些都需要一定的时间,我们可以使用多线程,不需要让用户一直等待这些任务的完成,就可以同时执行其他的一些操作.即使 ...

  8. Task1.数据集探索

    中文数据集THUCNews:https://pan.baidu.com/s/1hugrfRu 密码:qfud 参考:https://blog.csdn.net/SMith7412/article/de ...

  9. Codeforces 845D - Two TVs(贪心)

    原题链接:http://codeforces.com/problemset/problem/845/D 题意:一个人在驾照考试中,路边有“限速XX”.“没有限速”.“可以超车”.“不能超车”路牌, 以 ...

  10. [CSP-S模拟测试]:trade(反悔贪心)

    题目传送门(内部题62) 输入格式 第一行有一个整数$n$.第二行有$N$个整数:$a_1\ a_2\ a_3\cdot\cdot\cdot a_n$. 输出格式 一行一个整数表示最大收益. 样例 样 ...