CODEVS1291 火车线路
某列火车行使在C个城市之间(出发的城市编号为1,结束达到的城市的编号为C),假设该列火车有S个座位,现在有R笔预订票的业务。现在想对这R笔业务进行处理,看哪些预定能满足,哪些不能满足。
一笔预定由O、D、N三个整数组成,表示从起点站O到目标站D需要预定N个座位。一笔预定能满足是指该笔业务在行程范围内有能满足的空座位,否则就不能满足。一笔业务不能拆分,也就是起点和终点站不能更改,预定的座位数目也不能更改。所有的预定需求按给出先后顺序进行处理。
请你编写程序,看那些预定业务能满足,那些不能满足。
输入文件中的第一行为三个整数C、S、R,(1<=c<=60 000, 1<=s<=60 000, 1<=r<=60 000)他们之间用空隔分开。接下来的R行每行为三个整数O、D、N,(1<=o<d<=c, 1<=n<=s),分别表示每一笔预定业务。
对第I笔业务,如果能满足,则在输出文件中的第I行输出“T”,否则输出“N”
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<iomanip>
#include<string>
#include<climits>
#include<cmath>
#define MAX 110000
#define LL long long
using namespace std;
<<;
;
LL c,s,r;
LL ans,minv;
struct Tree
{
LL l,r;
LL sum,mmin,add;
};
Tree tree[MAX*];
void pushup(LL x)
{
LL tmp=*x;
tree[x].sum=tree[tmp].sum+tree[tmp+].sum;
tree[x].mmin=min(tree[tmp].mmin,tree[tmp+].mmin);
}
void pushdown(LL x)
{
LL tmp=*x;
tree[tmp].add+=tree[x].add;
tree[tmp+].add+=tree[x].add;
tree[tmp].mmin+=tree[x].add;
tree[tmp+].mmin+=tree[x].add;
tree[tmp].sum+=tree[x].add*(tree[tmp].r-tree[tmp].l+);
tree[tmp+].sum+=tree[x].add*(tree[tmp+].r-tree[tmp+].l+);
tree[x].add=;
}
void build(int l,int r,int x)
{
tree[x].l=l;
tree[x].r=r;
tree[x].add=;
if(l==r)
{
tree[x].sum=startVal+s;
tree[x].mmin=startVal+s;
return ;
}
;
;
build(l,mid,tmp);
build(mid+,r,tmp+);
pushup(x);
}
void update(LL l,LL r,LL c,LL x)
{
if(r<tree[x].l||l>tree[x].r)
return ;
if(l<=tree[x].l&&r>=tree[x].r)
{
tree[x].add+=c;
tree[x].sum+=c*(tree[x].r-tree[x].l+);
tree[x].mmin+=c;
return ;
}
if(tree[x].add)
pushdown(x);
LL tmp=x<<;
update(l,r,c,tmp);
update(l,r,c,tmp+);
pushup(x);
}
void query(LL l,LL r,LL x)
{
if(r<tree[x].l||l>tree[x].r)
return ;
if(l<=tree[x].l&&r>=tree[x].r)
{
ans+=tree[x].sum;
minv=min(minv,tree[x].mmin);
return ;
}
if(tree[x].add)
pushdown(x);
LL tmp=x<<;
LL mid=(tree[x].l+tree[x].r)>>;
if(r<=mid)
query(l,r,tmp);
else if(l>mid)
query(l,r,tmp+);
else
{
query(l,mid,tmp);
query(mid+,r,tmp+);
}
}
int main()
{
scanf("%lld %lld %lld",&c,&s,&r);
build(,c,);
while(r--)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);--b;/*!!!*/
update(a,b,-c,);
minv=inf;query(a,b,);
if(minv<startVal){
printf("N\n");
update(a,b,c,);
}else printf("T\n");
}
;
}
CODEVS1291 火车线路的更多相关文章
- codevs 1291 火车线路
http://codevs.cn/problem/1291/ 题目描述 Description 某列火车行使在C个城市之间(出发的城市编号为1,结束达到的城市的编号为C),假设该列火车有S个座位,现在 ...
- RMQ训练题 codevs 1291 火车线路 已经搞定
就是线段树维护区间的最小值 但是要注意 本题坑人的地方 是 a到b站 实际上是维护a到b-1 因为b站已经下车了 我勒个去呀 #include<iostream> #include ...
- iOS 1 到 iOS 10 ,我都快老了
iOS 1:iPhone诞生 虽然很难想像,但初代iPhone在问世时在功能方面其实远远落后于那时的竞争对手,比如Windows Mobile.Palm OS.塞班.甚至是黑莓.它不支持3G.多任务. ...
- ACdream 1103 瑶瑶正式成为CEO(树链剖分+费用流)
Problem Description 瑶瑶(tsyao)是某知名货运公司(顺丰)的老板,这个公司很大,货物运输量极大,因此公司修建了许多交通设施,掌控了一个国家的交通运输. 这个国家有n座城市,公司 ...
- [转] Symbol对象
GIS中的离散实体有三种:点.线.面,在ArcEngine中用三种符号对应表示,分别是:MarkSymbol.LineSymbol和FillSymbol.此外还有TextSymbol用于文字标注,3D ...
- Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路
D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 《javascript设计模式与开发实践》阅读笔记(14)—— 中介者模式
中介者模式 数个对象之间的通信全部委托一个中介者完成.适用于对象之间互相引用,关系错综复杂的情况. 什么情况下需要使用中介者模式 对象较多,且对象间会相互引用,当一个对象的某个状态改变时,得通知其他对 ...
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...
- 如果IBM再给我一次实习机会
2014年,我拿到了IBM斯图加特R&D的实习机会.在连续被索尼和博世拒掉之后,这个实习对我来说弥足珍贵.我学的是通信专业,在这之前与编程相关的活动只有一学期的安卓Lab,还是靠抱队友大腿才及 ...
随机推荐
- 【freemaker】之整合springMVC
pom.xml文件 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncod ...
- ARM Linux从Bootloader、kernel到filesystem启动流程
转自:http://www.veryarm.com/1491.html ARM Linux启动流程大致为:bootloader ---->kernel---->root filesyste ...
- PHP之单例模式的实现
单例模式: 单例模式又称职责模式:简单的说,一个对象(在学习设计模式之前,需要比较了解面向对象思想)只负责一个特定的任务: 单例类: 1.构造函数需要标记为private(访问控制:防止外部代码使用n ...
- 黄聪:wordpress/wp-includes目录文件
wp-includes/cache.php wp-includes/capabilities.php wp-includes/class-IXR.php:Incutio XML-RPC库.包括了 XM ...
- yarn的调度策略
一. yarn的资源分配模型 无论先进先出调度器,容量调度器,还是公平调度器,他们的核心:资源分配模型是一样的. 调度器维护着多个队列的信息,用户可以向任意一个或多个队列提交job.每次NodeMan ...
- 不用删除整个Maven本地库文件夹,Eclipse下直接更新Maven库
- MyEclipse-File Serarch时报错:Problems encountered during text search
- 最最简单的~WordCount¬
sc.textFile("hdfs://....").flatMap(line =>line.split(" ")).map(w =>(w,1)). ...
- Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- LR11
HP LoadRunner Readme for the Windows operating system Software version: 11.00 Publication date: Octo ...