线段树每个结点维护两个值,分别是这个区间的 负债 和 余钱。

按时间顺序从前往后看的时候,显然负债是单调不减的。

按时间顺序从后往前看的时候,显然余钱也是单调不减的,因为之前如果有余钱,可能会增加现在的余钱,但之前的负债不会减少现在的余钱。

所以线段树的区间合并这样做:

当前区间的负债 = 左区间的负债 + max(右区间的负债 - 左区间的余钱,0);

当前区间的余钱 = 右区间的余钱 + max(左区间的余钱 - 右区间的负债,0);

最后答案就是整个区间的负债。

代码自行脑补。

【线段树】Gym - 100507C - Zhenya moves from parents的更多相关文章

  1. Gym 100507C Zhenya moves from parents (线段树)

    Zhenya moves from parents 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/C Description Z ...

  2. ural2014 Zhenya moves from parents

    Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his parents’ h ...

  3. ural 2014 Zhenya moves from parents

    2014. Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his pare ...

  4. zhenya moves from parents

    Zhenya moved from his parents' home to study in other city. He didn't take any cash with him, he onl ...

  5. Gym 100507D Zhenya moves from the dormitory (模拟)

    Zhenya moves from the dormitory 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Descrip ...

  6. URAL 2014 Zhenya moves from parents --线段树

    题意:儿子身无分文出去玩,只带了一张他爸的信用卡,当他自己现金不足的时候就会用信用卡支付,然后儿子还会挣钱,挣到的钱都是现金,也就是说他如果有现金就会先花现金,但是有了现金他不会还信用卡的钱.他每花一 ...

  7. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  8. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  9. Codeforces Gym 100513F F. Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

随机推荐

  1. HTML5 canvas流体力学效果

    某人用Java搞了一个流体力学的演示:http://grantkot.com/MPM/Liquid.html. 下面是 HTML 5版的流体力学演示(推荐使用Chrome浏览器浏览): 效果演示 &l ...

  2. JavaScript渐变效果的实现

    鼠标移上去透明度渐渐增加,鼠标移出,透明度渐渐减小. 关键代码: view source   print? 1 var speed = 0; 2 if(target>obj.alpha){ 3 ...

  3. PHP报错Cannot adopt OID in UCD-SNMP-MIB、 LM-SENSORS-MIB

    Cannot adopt OID in UCD-SNMP-MIB: Cannot adopt OID in LM-SENSORS-MIB: lmTempSensorsValue 运行PHP遇到这些错误 ...

  4. elementUi 组件--el-table

    [需求]在element中,将表格中的数据进行处理,然后渲染出来.例如,将数据保留小数点后两位显示. [知识点]formatter:用来格式化内容 [分析]在element 的table中,实现的过程 ...

  5. BZOJ 2095: [Poi2010]Bridges

    2095: [Poi2010]Bridges Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 869  Solved: 299[Submit][Stat ...

  6. npm install 报node-sass错误

    Node Sass could not -bit with Node.js .x Found bindings for the following environments: - OS X -bit ...

  7. MySQL 之 foreign key

    前段回顾 create table 表名( 字段名1 类型[(宽度) 约束条件], 字段名2 类型[(宽度) 约束条件], 字段名3 类型[(宽度) 约束条件] ); #解释: 类型:使用限制字段必须 ...

  8. jQuery九宫格图片拉伸变大代码

    之前看到网上有jQuery九宫格图片拉伸变大代码只可以动六张图片,我改了改做了九张图片都可以做的 图片的布局 成品就是每一个图片都可以动看到大图 css样式 <style> /*九宫格*/ ...

  9. SVN被锁定解决办法

    转自:https://blog.csdn.net/strwangfan/article/details/78748393: 今天用SVN的时候出现被锁定的情况,既不能更新代码也不能提交. 解决方法如下 ...

  10. 3.flask视图进阶

    1.add_url_rule和app.route原理剖析 from flask import Flask app = Flask(__name__) # 下面是我们定义一个路由和对应视图的常用方法 ' ...