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 ...
随机推荐
- nginx+vite 项目打包及部署到服务器二级路由
项目打包及部署到服务器二级路由 例如:我希望将打包的项目部署到 http://localhost:8088/web/ 上 一. 项目配置及打包 项目部署到服务器二级路由需要配置基础路径base,即需要 ...
- ICMP隐蔽隧道攻击分析与检测(四)
• ICMP隧道攻击通讯特征和特征提取 一.ICMP Ping正常通讯特征总结 一个正常的 ping 每秒最多只会发送两个数据包,而使用 ICMP隧道的服务器在同一时间会产生大量 ICMP 数据包 正 ...
- 图与网络分析—R实现(三)
最小生成树 (Minimum Spanning Tree) 应该大家都不陌生,Spanning 有跨越的意思,生成树一般来说每个节点都能访问到别的节点,是一个连通树.所以,一般考虑无向图里去造生成树. ...
- [Linux/Git]比较两份文件的差异
Command vim -d fileA fileB 或 git diff <oldCommitId> <newCommitId> X Recommend Files Matc ...
- Vue修改单页面背景颜色
- C++核心知识回顾(函数&参数、异常、动态分配)
复习C++的核心知识 函数与参数 传值参数.模板函数.引用参数.常量引用参数 传值参数 int abc(int a,int b,int c) { return a + b * c; } a.b.c是函 ...
- 一个基于Java线程池管理的开源框架Hippo4j实践
@ 目录 概述 定义 线程池痛点 功能 框架概览 架构 部署 Docker安装 二进制安装 运行模式 依赖配置中心 接入流程 个性化配置 线程池监控 无中间件依赖 接入流程 服务端配置 三方框架线程池 ...
- 1748E Yet Another Array Counting Problem
1748E Yet Another Array Counting Problem 目录 1748E Yet Another Array Counting Problem 题目大意: 做法 code 题 ...
- 揭开神秘面纱,会stream流就会大数据
目录 准备工作 1.map类 1.1 java stream map 1.2 spark map 1.2.1 MapFunction 1.2.2 MapPartitionsFunction 2.fla ...
- Reshaper 代码清理工具
reshaper是个好工具,能帮助我们提升开发效率,比如本文要介绍的全局代码清理功能. 如果你的VS安装了reshaper,可以通过Ctrl+E+C快捷键打开代码清理窗口. 代码清理,可以格式化多种文 ...