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 ...
随机推荐
- fiddler提示"The system proxy was changed,click to reenable fiddler capture"的解决方法
之前用fiddler 一直都是正常的,但是过了几个月再次使用的时候没几秒钟就提示:The system proxy was changed,click to reenable fiddler capt ...
- MyBatis01:框架概述、环境搭建及入门案例、自定义框架
课程介绍 第一天:mybatis的入门 mybatis的概述 mybatis的环境搭建 mybatis入门案例 自定义mybatis框架(目的:了解mybatis的执行细节) 第二天:mybatis基 ...
- 【每日一题】【暴力、动态规划、动规优化、贪心】2022年1月21日-NC19 连续子数组的最大和/最大子序和
同:最大子序和 https://www.cnblogs.com/liujinhui/p/15574312.html 描述输入一个长度为n的整型数组array,数组中的一个或连续多个整数组成一个子数组. ...
- SQL注入问题/触发器trigger/事务/事物隔离
SQL注入问题 本质:利用特殊符号的组合产生特殊的含义,从而避开正常的业务逻辑 select * from userinfo where name='jason' -- kasdjksajd' and ...
- python + mysql +djagno +unittest 实现WEB、APP UI自动化测试平台--------(一)基础表
from django.db import models # Create your models here. class DictConfig(models.Model): "" ...
- jmeter 之性能分布式压测
背景: 当并发量达到一定数量时,单台测试设备不足以支撑,甚至会出现内存溢出等情况,解决这个问题就可用分布式测试,使用多台测试设备来达到更大的用户并发数. 原理: 1.一台设备作为调度机(master) ...
- IntelliJ IDEA中我最爱的10个快捷操作
前言 欢迎关注微信公众号「JAVA旭阳」交流和学习 IntelliJ IDEA提供了一些Java的快捷键,同样也可以帮助我们提高日常的开发效率.关于这些快捷操作,你知道那几个呢? 1. psvm/ma ...
- JavaScript:操作符:逻辑运算符及其隐式转换数据类型
逻辑非! 用来对布尔值进行取反,即!true = false: 当取反的变量不是布尔值,会进行隐式转换为布尔值: 非0的数字,都转换为true 非空字符串,转换为true 非空对象,转换为true I ...
- 14、java.sql.SQLException: 无效的列类型: 1111 报错问题解决
转载自 在项目中利用Mybatis做持久化框架,XXXMapper.xml中insert语句做插入时,偶然会遇到一些报错或者说是问题,如下: 一.报错日志: nested exception is o ...
- [python] 基于paramiko库操作远程服务器
SSH(Secure Shell)是一种网络安全协议,能够使两台计算机安全地通信和共享数据.目前,SSH协议已在世界各地广泛使用,大多数设备都支持SSH功能.SSH的进一步说明见:深入了解SSH.SS ...