CF1250C Trip to Saint Petersburg
思路
线段树入门题。
不妨固定一个右端点 \(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的更多相关文章
- Codeforces1250C Trip to Saint Petersburg 线段树
题意 有个人要去圣彼得堡旅游,在圣彼得堡每天要花\(k\)块钱,然后在圣彼得堡有\(n\)个兼职工作\(l_i,r_i,p_i\),如果这个人在\(l_i\)到\(r_i\)这个时间段都在圣彼得堡,那 ...
- 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 ...
- Using Headless Mode in the Java SE Platform--转
原文地址: By Artem Ananiev and Alla Redko, June 2006 Articles Index This article explains how to use ...
- UI中经常出现的下拉框下拉自动筛选效果的实现
小需求是当你在第一个下拉框选择了国家时,会自动更新第二个省份的下拉框,效果如下 两个下拉选择Html如下: <select id="country_select"> & ...
- uva 1605 building for UN ——yhx
The United Nations has decided to build a new headquarters in Saint Petersburg, Russia. It will have ...
- python爬虫爬取全球机场信息
--2013年10月10日23:54:43 今天需要获取机场信息,发现一个网站有数据,用爬虫趴下来了所有数据: 目标网址:http://www.feeyo.com/airport_code.asp?p ...
- The 50 Most Essential Pieces of Classical Music
1. Die Zauberflöte ("The Magic Flute"), K. 620: Overture London Philharmonic Orchestra 7:2 ...
- Kettle ETL 来进行mysql 数据同步——试验环境搭建(表中无索引,无约束,无外键连接的情况)
今天试验了如何在Kettle的图形界面(Spoon)下面来整合来mysql 数据库中位于不同数据库中的数据表中的数据. 试验用的数据表是customers: 第三方的数据集下载地址是:http://w ...
- UVa1605 - Building for UN(构造法)
UVA - 1605 Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Description ...
- UVA1605-Building for UN(思维)
Problem UVA1605-Building for UN Accept: 398 Submit: 2303Time Limit: 10000 mSec Problem Description ...
随机推荐
- redux原理分享
概述 一个状态管理工具 Store:保存数据的地方,你可以把它看成一个容器,整个应用只能有一个 Store. State:包含所有数据,如果想得到某个时点的数据,就要对 Store 生成快照,这种时点 ...
- Python异步协程(asyncio详解)
续上篇讲解yield from博客,上篇链接:https://www.cnblogs.com/Red-Sun/p/16889182.html PS:本博客是个人笔记分享,不需要扫码加群或必须关注什么的 ...
- 数电第11周周结_by_yc
Lab7_时序逻辑验证 一.简易电子时钟 功能描述: 设计一简易电子时钟,支持时.分.秒显示,其中HEX7-HEX6显示时,HEX5-HEX4显示分,HEX1-HEX0显示秒,假设进制为:18秒= ...
- On Java 8读书笔记
第一章 什么是对象 1.1 抽象的历程 "对象":问题空间中的元素及其解决方案空间中的具体呈现. 理念即是通过添加各种新的对象,可以将程序改编为一种描述问题的语言. 对象是具有状态 ...
- postgresql函数:满足特定格式的表及指定日期前的删除
-- 一.现有函数-- 1.现有函数调用select "ap"."delete_analysis_backup"('ap');-- 2.函数内容CREATE O ...
- 云原生 • Kubernetes 认识 k8s、k8s 架构、核心概念点介绍
云原生 • Kubernetes 认识 k8s.k8s 架构.核心概念点介绍 一.Kubernetes 简介Kubernetes 简称 k8s,是支持云原生部署的一个平台,起源于谷歌.谷歌早在十几年之 ...
- PyQt4编写界面的两种方式
PyQt4编写界面的两种方式 应用PyQt4开发图形化界面有两种方式,一种是直接通过QtDesigner通过提供的窗口部件拖拽进行GUI创建,另外一种是直接进行编程实现. 第一种,QtDesigner ...
- 网络编程 - OSI七层协议详解
目录 网络编程基础 软件开发架构 网络编程简介 OSI七层协议简介 OSI协议之物理连接层 OSI协议之数据链路层 网络相关专业名词 OSI之网络层 OSI协议之传输层 传输层之TCP协议/UDP协议 ...
- HMS Core 6.8.0版本发布公告
分析服务 ◆ 游戏行业新增"区服分析"埋点模板及分析报告,支持开发者分服务器查看用户付费.留存等指标,可进一步评估不同服务器的玩家质量: ◆ 新增营销活动报告,可查看广告任务带来的 ...
- codeforce E - Binary Inversions题解
题目: 给你一个01串,现在你可以(或者不用)选取其中一个元素进行一次反转操作0-1,1-0:从而使得串中的逆序对个数最多. 题目链接:codeforce origin problem 思路: 1. ...