P1607 [USACO09FEB]庙会班车Fair Shuttle

题目描述

Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his cows are not in such good shape; a full day of walking around the fair leaves them exhausted. To help them enjoy the fair, FJ has arranged for a shuttle truck to take the cows from place to place in the fairgrounds.

FJ couldn't afford a really great shuttle, so the shuttle he rented traverses its route only once (!) and makes N (1 <= N <= 20,000) stops (conveniently numbered 1..N) along its path. A total of K (1 <= K <= 50,000) groups of cows conveniently numbered 1..K wish to use the shuttle, each of the M_i (1 <= M_i <= N) cows in group i wanting to ride from one stop S_i (1 <= S_i < E_i) to another stop E_i (S_i < E_i <= N) farther along the route.

The shuttle might not be able to pick up an entire group of cows (since it has limited capacity) but can pick up partial groups as appropriate.

Given the capacity C (1 <= C <= 100) of the shuttle truck and the descriptions of the groups of cows that want to visit various sites at the fair, determine the maximum number of cows that can ride the shuttle during the fair.

逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼——如果要逛完一整天的集市,他们一定会筋疲力尽的。所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛们在集市上以车代步。但是,约翰木有钱,他租来的班车只能在集市上沿直线跑一次,而且只能停靠N(1 ≤N≤20000)个地点(所有地点都以1到N之间的一个数字来表示)。现在奶牛们分成K(1≤K≤50000)个小组,第i 组有Mi(1 ≤Mi≤N)头奶牛,他们希望从Si跑到Ti(1 ≤Si<Ti≤N)。

由于班车容量有限,可能载不下所有想乘车的奶牛们,此时也允许小里的一部分奶牛分开乘坐班车。约翰经过调查得知班车的容量是C(1≤C≤100),请你帮助约翰计划一个尽可能满足更多奶牛愿望的方案。

输入输出格式

输入格式:

【输入】

第一行:包括三个整数:K,N和C,彼此用空格隔开。

第二行到K+1行:在第i+1行,将会告诉你第i组奶牛的信息:Si,Ei和Mi,彼

此用空格隔开。

输出格式:

【输出】

第一行:可以坐班车的奶牛的最大头数。

输入输出样例

输入样例#1:

8 15 3
1 5 2
13 14 1
5 8 3
8 14 2
14 15 1
9 12 1
12 15 2
4 6 1
输出样例#1:

10

说明

【样例说明】

班车可以把2头奶牛从1送到5,3头奶牛从5送到8,2头奶牛从8送到14,1头

奶牛从9送到12,1头奶牛从13送到14,1头奶牛从14送到15。

/*
优先选结束位置最小的,能选就选,然后就是怎么判断是否可以选,那么可以选的条件是这个组的[L,R]之间的最大值加上这个组的人不会超过最大容量C,所以维护一个区间最大值就好,如果塞不进,能塞多少是多少,本蒟蒻用的是线段树,然后每一次选完后就在线段树中[L,R-1] 加上这个组的人数即可
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#define maxn 50010
using namespace std;
int n,m,c,opl,opr,opv,ans;
struct node{
int l,r,v;
bool operator < (const node b)const{
if(r!=b.r)return r<b.r;
return l>b.l;
}
}a[maxn];
struct Node{
int l,r,v,lazy;
}tr[maxn*];
void build(int l,int r,int k){
tr[k].l=l;tr[k].r=r;
if(l==r)return;
int mid=(l+r)>>;
build(l,mid,k<<);
build(mid+,r,k<<|);
}
void updata(int k){
tr[k<<].lazy+=tr[k].lazy;
tr[k<<|].lazy+=tr[k].lazy;
tr[k<<].v+=tr[k].lazy;
tr[k<<|].v+=tr[k].lazy;
tr[k].lazy=;
}
int query(int l,int r,int opl,int opr,int k){
if(l>=opl&&r<=opr)return tr[k].v;
if(tr[k].lazy)updata(k);
int mid=(l+r)>>,res=;
if(opl<=mid)res=max(res,query(l,mid,opl,opr,k<<));
if(opr>mid)res=max(res,query(mid+,r,opl,opr,k<<|));
tr[k].v=max(tr[k<<].v,tr[k<<|].v);
return res;
}
void change(int l,int r,int opl,int opr,int k,int v){
if(l>=opl&&r<=opr){
tr[k].v+=v;
tr[k].lazy+=opv;
return;
}
if(tr[k].v)updata(k);
int mid=(l+r)>>;
if(opl<=mid)change(l,mid,opl,opr,k<<,v);
if(opr>mid)change(mid+,r,opl,opr,k<<|,v);
tr[k].v=max(tr[k<<].v,tr[k<<|].v);
}
int main(){
freopen("Cola.txt","r",stdin);
scanf("%d%d%d",&m,&n,&c);
build(,n,);
for(int i=;i<=m;i++)scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].v);
sort(a+,a+m+);
for(int i=;i<=m;i++){
opl=a[i].l,opr=a[i].r;
int mx=query(,n,opl,opr,);
if(mx>=c)continue;
if(mx+a[i].v<=c)opv=a[i].v;
else opv=c-mx;
ans+=opv;
opr--;
change(,n,opl,opr,,opv);
}
printf("%d",ans);
}

洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle的更多相关文章

  1. 洛谷 P1607 [USACO09FEB]庙会班车Fair Shuttle 解题报告

    P1607 [USACO09FEB]庙会班车Fair Shuttle 题目描述 Although Farmer John has no problems walking around the fair ...

  2. 【贪心】洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle 题解

        不是很容易写出正解的贪心问题. 题目描述 Although Farmer John has no problems walking around the fair to collect pri ...

  3. P1607 [USACO09FEB]庙会班车Fair Shuttle

    题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...

  4. 线段树【p1607】[USACO09FEB]庙会班车Fair Shuttle

    Description 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼--如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛 ...

  5. [USACO09FEB]庙会班车Fair Shuttle 线段树维护maxx&&贪心

    题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...

  6. [USACO09FEB]庙会班车Fair Shuttle

    题目描述 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼——如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛们在集市上以车 ...

  7. 【USACO09FEB】 庙会班车 Fair Shuttle 贪心+线段树

    Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his ...

  8. 【Luogu】P1607庙会班车Fair Shuttle(线段树+贪心)

    我不会做贪心题啊……贪心题啊……题啊……啊…… 我真TM菜爆了啊…… 这题就像凌乱的yyy一样,把终点排序,终点相同的按起点排序.然后维护一个查询最大值的线段树.对于一个区间[l,r],如果这个区间已 ...

  9. [洛谷P1607] 庙会班车

    题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...

随机推荐

  1. Raft 为什么是更易理解的分布式一致性算法——(1)Leader在时,由Leader向Follower同步日志 (2)Leader挂掉了,选一个新Leader,Leader选举算法。

    转自:http://www.cnblogs.com/mindwind/p/5231986.html Raft 协议的易理解性描述 虽然 Raft 的论文比 Paxos 简单版论文还容易读了,但论文依然 ...

  2. 机器学习:YOLO for Object Detection (一)

    最近看了基于CNN的目标检测另外两篇文章,YOLO v1 和 YOLO v2,与之前的 R-CNN, Fast R-CNN 和 Faster R-CNN 不同,YOLO 将目标检测这个问题重新回到了基 ...

  3. linux 故障:df -h统计磁盘空间占用太多,但又du -h找不到大的文件

    用lsof / | grep -i delete 从根目录定位打开的被删除的文件 如果定位到某文件占用空间很大 主要是因为我们在删除这个日志文件的时候是用rm -rf *.log这样的命令删除的,删除 ...

  4. linux 在后台运行数据库导入导出命令

    nohup imp dbusername/password@orcl file=/home/20170928.dmp ignore=y log=/home/oracle/20170928.log fu ...

  5. 【JVM】jvm垃圾回收器相关垃圾回收算法

    引用计数法[原理]--->引用计数器是经典的也是最古老的垃圾收集防范.--->实现原理:对于对象A,只要有任何一个对象引用A,则计数器加1.当引用失效时,计数器减1.只要对象A的计数器值为 ...

  6. ACM学习历程—CodeForces 601A The Two Routes(最短路)

    题目链接:http://codeforces.com/problemset/problem/601/A 题目大意是有铁路和陆路两种路,而且两种方式走的交通工具不能在中途相遇. 此外,有铁路的地方肯定没 ...

  7. docker-ce安装与搭建私有仓库

    https://www.cnblogs.com/sszhou/p/7389144.html 系统环境centos7 ###docker-ce安装###1.卸载老版本,较老版本的Docker被称为doc ...

  8. Sublime Text 全程指南(转载)

    摘要(Abstract) 本文系统全面的介绍了Sublime Text,旨在成为最优秀的Sublime Text中文教程. 更新记录 2014/09/27:完成初稿 2014/09/28: 更正打开控 ...

  9. Poj1062 昂贵的聘礼 (dijkstra算法)

    一.Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长 ...

  10. 用Raspberry Pi搭建Azure IOT解决方案

    Raspberry Pi是一款基于Linux的单板机电脑.它由英国的树莓派基金会所开发,目的是以低价硬件及自由软件刺激在学校的基本计算机科学教育.树莓派配备一枚博通(Broadcom)出产的ARM架构 ...