CF1034D Intervals of Intervals
简要题意
给定 \(n\) 个区间组成的序列,定义它的一个连续段的价值为这个段内所有区间的并覆盖的长度。求价值前 \(k\) 大的段的价值和。
数据范围:\(1\le n\le 3\times 10^5, 1\le k\le \min\{\frac{n(n-1)}{2}, 10^9\}\)。
题解
考虑一个经典问题,\(q\) 次询问求某个连续段的价值。考虑离线,动态维护对于当前右端点,每个左端点的答案。考虑一个位置最后一次被覆盖是在第 \(t\) 个区间,那么对于所有 \(1\le l\le t\) 这个位置都会贡献 \(1\)。那么考虑将右端点右移一位时如何维护。显然类似珂朵莉树,可以证明修改段的次数是均摊 \(\mathrm O(n)\)。那么直接考虑用线段树,修改段等价于一次区间加。总时间复杂度 \(\mathrm O(n\log n)\)。把线段树换成主席树,可以做到在线询问。
接着考虑这题,容易想到先找到排名为 \(k\) 的连续段的价值,就很好做了,那么二分答案,转化为计数价值大于 \(X\) 的连续段。考虑一个结论:\(V(L_i, R_i + 1)\ge V(L_i, R_i) \ge V(L_i + 1, R_i)\)。则存在 \(pos(r, X)\) 为最大的 \(l\) 使得 \(V(l, r) > X\)。同时容易得出,\(V(r, X)\) 关于 \(r\) 单增。通过一个指针维护,把珂朵莉树放在二分外面,预处理出每个 \(r\) 增加的区间,用前缀和维护即可,时间复杂度 \(\mathrm O(n\log n)\)。
CF1034D Intervals of Intervals的更多相关文章
- [LeetCode] Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- [LeetCode] Merge Intervals 合并区间
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...
- Leetcode Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- Merge Intervals 运行比较快
class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...
- [LeetCode] 435 Non-overlapping Intervals
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- 【leetcode】Merge Intervals
Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given ...
- 【leetcode】Merge Intervals(hard)
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- leetcode56. Merge Intervals
题目要求: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6 ...
- Leetcode: Non-overlapping Intervals
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
随机推荐
- 单机最快的队列Disruptor解析和使用
前言 介绍高性能队列Disruptor原理以及使用例子. Disruptor是什么? Disruptor是外汇和加密货币交易所运营商 LMAX group 建立高性能的金融交易所的结果.用于解决生产者 ...
- [J2EE:中间件]LOG4J+Slf4J快速入门及日志最佳实践
1 概述 1.1 常见的Java日志框架及选择 commons-logging和slf4j(slf4j-api.jar)都是日志类库的接口,供客户端使用,而没有提供实现! log4j,logback等 ...
- Luogu P4114 Qtree1
树剖一好题.我心水了ww 题目描述 给定一棵n个节点的树,有两个操作: CHANGE i ti 把第i条边的边权变成ti QUERY a b 输出从a到b的路径中最大的边权,当a=b的时候,输出0 输 ...
- vue表单绑定v-model
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- day02-Redis命令
Redis命令 1.Redis数据结构介绍 Redis是一个key-value的数据库,key一般是String类型,value的类型多种多样,value常见的八种类型: Redis支持五种基本的数据 ...
- Django笔记二十六之数据库函数之数学公式函数
本文首发于公众号:Hunter后端 原文链接:Django笔记二十六之数据库函数之数学公式函数 这一篇来介绍一下公式函数,主要是数学公式. 其中 sin,cos 这种大多数情况下用不上的就不介绍了,主 ...
- Shell脚本编程(二)
Shell脚本编程(二) shell脚本编程中if.if else的使用以及一些常用到的操作符 if.if else使用方式: 1) if条件 if [ condition ...
- 突破tls/ja3新轮子
我之前的文章介绍了SSL指纹识别 https://mp.weixin.qq.com/s/BvotXrFXwYvGWpqHKoj3uQ 很多人来问我BYPass的方法 主流的BYPASS方法有两大类: ...
- 虚拟机的安装与linux系统的使用
虚拟机的安装与应用 下载安装VMware Workstation Pro 安装成功之后点击创建虚拟机 勾选典型机型 勾选自动检测安装映像文件 设置虚拟机的命名和安装路径 设置磁盘的大小和虚拟磁盘的储存 ...
- Web进阶LNMP网站部署
Web进阶LNMP网站部署 目录 Web进阶LNMP网站部署 LNMP架构工作流程 部署LNMP架构 1.安装nginx 2.安装php 3.安装数据库 将Nginx和PHP建立连接 1.修改ngin ...