传送门

显然可以考虑 $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. 2018-8-27-C#-powshell-调用

    title author date CreateTime categories C# powshell 调用 lindexi 2018-8-27 16:20:4 +0800 2018-06-18 20 ...

  2. 线上nginx 平滑添加新模块;如(--with-http_realip_module)

    nginx 添加模块1.查看当前nginx信息(配置文件路径,启动用户...) ps aux | grep nginx 2.查看当前nginx已启用的模块(记录模块信息,安装路径)./nginx -V ...

  3. [php代码审计] 哈希长度拓展攻击

    已知: 1. salt的长度. 2. message==“adminadmin”. 3. MD5(salt+message)的值. 求: MD5(salt+message+填充数据+任意字符串)的值. ...

  4. css3 :enabled与:disabled伪类选择器

    css :enabled和:disabled伪类选择器 在Web表单中,有些表单元素(如输入框.密码框.复选框等)有“可用”和“不可用”这2种状态.默认情况下,这些表单元素都处在可用状态. 在CSS3 ...

  5. CSS3 flexbox弹性布局实例

    常用例子 1.居中对齐 <!DOCTYPE html> <head> <meta charset="utf-8"> <style type ...

  6. flask之url_for函数

    一:url_for函数 干什么的?传入函数名,得到函数的路由地址(访问视图函数的地址) from flask import Flask from flask import url_for app = ...

  7. basic deepwalk

    Get to know How deepwalk works by this project. Two steps: 1. gen the graph, and gen the corpus on t ...

  8. Keyguard分析

      从Android 6.0开始,位于frameworks/bases/packages/Keyguard的Keyguard开始被编译为一个jar包,被SystemUI静态导入,相当于SystemUI ...

  9. 【HDOJ6667】Roundgod and Milk Tea(模拟)

    题意:有n个班级,每个班级有a[i]个人,b[i]杯奶茶 每个人至多喝一杯奶茶,且不能喝自己班的 问能喝到奶茶的最多总人数 n<=1e6,a[i],b[i]<=1e9 思路: 做法一: # ...

  10. 循序渐进实现仿QQ界面(二):贴图按钮的三态模拟

    开始之前先说一下RingSDK的编译问题,这里演示的程序需要用到最新版本的RingSDK,请务必用SVN到svn://svnhost.cn/RingSDK更新到最新版本,推荐用TortoiseSVN. ...