题目传送门

思路

线段树入门题。

不妨固定一个右端点 \(r\),把所有右端点小于 \(r\) 的区间都在 \(1\) 至此区间的左端点处 update 一个 \(p\),然后每次都给区间 \(1\) 至 \(i\) update 一个 \(-k\),最后查询区间 \(\max\) 即可。

代码

//A tree without skin will surely die.
//A man without face is invincible.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int const N=2e5+10;
struct answ{int first,second,id;};
struct node{int x,y;};
vector<answ>a[N];
vector<int>anss;
struct Segment_Tree{
#define ls (x<<1)
#define rs (x<<1|1)
#define mid ((l+r)>>1)
int c[N<<2],lazy[N<<2],pl[N<<2];
inline void build(int x,int l,int r){
if (l==r){pl[x]=l;return;}
build(ls,l,mid);build(rs,mid+1,r);
pl[x]=pl[ls];
}
inline void pushdown(int x){
c[ls]+=lazy[x];c[rs]+=lazy[x];
lazy[ls]+=lazy[x];lazy[rs]+=lazy[x];
lazy[x]=0;
}
inline void pushup(int x){
if (c[ls]>c[rs]) c[x]=c[ls],pl[x]=pl[ls];
else c[x]=c[rs],pl[x]=pl[rs];
}
inline void update(int x,int l,int r,int ll,int rr,int v){
if (l==r){pl[x]=l;}
if (ll<=l && r<=rr){c[x]+=v,lazy[x]+=v;return;}
pushdown(x);
if (ll<=mid) update(ls,l,mid,ll,rr,v);
if (mid<rr) update(rs,mid+1,r,ll,rr,v);
pushup(x);
}
inline node query(int x,int l,int r,int ll,int rr){
if (l==r) pl[x]=l;
if (ll<=l && r<=rr) return {c[x],pl[x]};
pushdown(x);node res;res.x=res.y=0;
if (ll<=mid) res=query(ls,l,mid,ll,rr);
if (mid<rr){
node qq=query(rs,mid+1,r,ll,rr);
if (qq.x>res.x) res=qq;
}
pushup(x);
return res;
}
}T;
signed main(){
int n,k;cin>>n>>k;int maxr=0;
for (int i=1;i<=n;++i){
int l,r,p;cin>>l>>r>>p;
a[r].push_back({l,p,i});maxr=max(maxr,r);
}
T.build(1,1,maxr);
int ans=0,ansl=0,ansr=0;
for (int i=1;i<=maxr;++i){
T.update(1,1,maxr,1,i,-k);
for (auto j:a[i]) T.update(1,1,maxr,1,j.first,j.second);
node reply=T.query(1,1,maxr,1,i);
if (reply.x>ans) ans=reply.x,ansl=reply.y,ansr=i;
}
//输出
return 0;
}

CF1250C Trip to Saint Petersburg的更多相关文章

  1. Codeforces1250C Trip to Saint Petersburg 线段树

    题意 有个人要去圣彼得堡旅游,在圣彼得堡每天要花\(k\)块钱,然后在圣彼得堡有\(n\)个兼职工作\(l_i,r_i,p_i\),如果这个人在\(l_i\)到\(r_i\)这个时间段都在圣彼得堡,那 ...

  2. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest

    目录 Contest Info Solutions A. Berstagram B. The Feast and the Bus C. Trip to Saint Petersburg E. The ...

  3. Using Headless Mode in the Java SE Platform--转

    原文地址: By Artem Ananiev and Alla Redko, June 2006     Articles Index This article explains how to use ...

  4. UI中经常出现的下拉框下拉自动筛选效果的实现

    小需求是当你在第一个下拉框选择了国家时,会自动更新第二个省份的下拉框,效果如下 两个下拉选择Html如下: <select id="country_select"> & ...

  5. uva 1605 building for UN ——yhx

    The United Nations has decided to build a new headquarters in Saint Petersburg, Russia. It will have ...

  6. python爬虫爬取全球机场信息

    --2013年10月10日23:54:43 今天需要获取机场信息,发现一个网站有数据,用爬虫趴下来了所有数据: 目标网址:http://www.feeyo.com/airport_code.asp?p ...

  7. The 50 Most Essential Pieces of Classical Music

    1. Die Zauberflöte ("The Magic Flute"), K. 620: Overture London Philharmonic Orchestra 7:2 ...

  8. Kettle ETL 来进行mysql 数据同步——试验环境搭建(表中无索引,无约束,无外键连接的情况)

    今天试验了如何在Kettle的图形界面(Spoon)下面来整合来mysql 数据库中位于不同数据库中的数据表中的数据. 试验用的数据表是customers: 第三方的数据集下载地址是:http://w ...

  9. UVa1605 - Building for UN(构造法)

    UVA - 1605 Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description ...

  10. UVA1605-Building for UN(思维)

    Problem UVA1605-Building for UN Accept: 398  Submit: 2303Time Limit: 10000 mSec Problem Description ...

随机推荐

  1. org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents

    异常:org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to b ...

  2. dubbo2升级到dubbo3实践

    dubbo当前版本 2.7.3 期望升级到 3.0.11. 升级过程 maven依赖变更 <dependency> <groupId>org.apache.dubbo</ ...

  3. 解析【.mdb】文件

    有一些项目用的是微软的access软件,这里面存放数据用的是mdb结尾的文件 有的时候,客户想开发一个新的系统,但是数据需要从这些文件中获取,因此得解析这些文件,来提取数据 一.解析时用到的依赖 1. ...

  4. VMware虚拟机开机黑屏解决方法

    挂起时可以看到显示,但是开机就黑屏 解决方法: 命令提示符,鼠标右键点击"命令提示符",弹出菜单之后选择"以管理员身份运行" 在命令提示符窗口中输入" ...

  5. react 高效高质量搭建后台系统 系列 —— 脚手架搭建

    其他章节请看: react 高效高质量搭建后台系统 系列 脚手架搭建 本篇主要创建新项目 myspug,以及准备好环境(例如:安装 spug 中用到的包.本地开发和部署.自定义配置 react-app ...

  6. 用 while 生成猜数字

    import java.util.Random; import java.util.Scanner; public class zy2 { public static void main(String ...

  7. 结合商业项目深入理解Go知识点

    这篇文章比较硬核,爆肝5千字,把之前整理的知识点都串起来了.建议先收藏,慢慢看. 前言 上一篇文章 #[Go WEB进阶实战]开源的电商前后台API系统 很受大家欢迎,有好多小伙伴私信我问题:&quo ...

  8. 基于docker容器的MySQL主从设置及efcore读写分离

    1.基于docker部署MySQL,设置主从 本操作基于已经拉取的镜像(docker pull mysql) 创建一主一从两个数据库容器 docker run -d -p 3307:3306 -e M ...

  9. 【Linux】TCS34725 颜色传感器设备驱动

    一.概述 此笔记主要是学习 Linux 中的 I2C 驱动,顺便验证一下 TCS34725 传感器的使用,主要内容还是程序记录,方便编写其他 I2C 设备驱动时做参考,所以关于 TCS34725 这里 ...

  10. python实现单向循环链表与双向链表

    目录 单向循环链表 操作 实现 双向链表 操作 实现 单向循环链表 单链表的一个变形是单向循环链表,链表中最后一个节点的next域不再为None,而是指向链表的头节点. 操作 is_empty() 判 ...