题目传送门

思路

线段树入门题。

不妨固定一个右端点 \(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. APACHE正向代理配置

    Apache快速安装和反向代理配置:https://www.cnblogs.com/brad93/p/16718104.html Apache正向代理配置参考教程:https://www.cnblog ...

  2. 【云原生 • Docker】mysql、tomcat、nginx、redis 环境部署

    注意在应用部署之前,docker 服务必须是开启状态 systemctl start docker. 目录 一.MySQL 部署 二.Tomcat 部署 三.Nginx 部署 四.Redis 部署 一 ...

  3. NavigationDuplicated Navigating to current location (“/XXX”) is not allowed

    导航不允许导航到当前位置https://stackoverflow.com/questions/57837758/navigationduplicated-navigating-to-current- ...

  4. 一键部署MySQL8+keepalived双主热备高可用

    概述 本次的文章会格外的长,网上大多的配置流程已经不可使用,本篇文章可以称为保姆级教程,而且通过shell脚本大大减少了部署mysql主从,双主的工作量. 如上图,VIP地址为192.168.10.1 ...

  5. 【Java】从头开始学新的编程语言

    本文自用,Java入门笔记 -每个类都要在自己的单独文件中-我大为震撼 能运行的最小的Java程序要有main函数 public static void main(String[] args) (id ...

  6. 二阶段目标检测网络-Faster RCNN 详解

    Faster RCNN 网络概述 Conv layers RPN 网络 Anchors 生成 RPN 网络训练集 positive/negative 二分类 RPN 生成 RoIs(Proposal ...

  7. m3u8文件后缀jpg,png等处理方法及视频合并

    处理 # 解析伪装成png的ts def resolve_ts(src_path, dst_path): ''' 如果m3u8返回的ts文件地址为 https://p1.eckwai.com/ufil ...

  8. python内存机制

    内存机制 先从较浅的层面来说,Python的内存管理机制可以从三个方面来讲 (1)垃圾回收 (2)引用计数 (3)内存池机制 一.垃圾回收: python不像C++,Java等语言一样,他们可以不用事 ...

  9. Javaweb后端学习笔记

    C/S结构与B/S结构: 1.C/S(Client/Server)结构:适用于个人娱乐市场[QQ等] (1).优点:安全性高.且有效降低服务器压力: (2).不足:增加服务成本.更新较繁琐: 2.B/ ...

  10. AcWing第85场周赛

    这场周赛是手速局hh 死或生 某国正在以投票的方式决定 2 名死刑犯(编号 1∼2)的生死. 共有 n 组人员(编号 1∼n)参与投票,每组 10 人. 每组成员只参与一名死刑犯的投票,其中第 i 组 ...