简要题意

给定 \(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的更多相关文章

  1. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  2. [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  3. [LeetCode] Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  4. Leetcode Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  5. Merge Intervals 运行比较快

    class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...

  6. [LeetCode] 435 Non-overlapping Intervals

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  7. 【leetcode】Merge Intervals

    Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given  ...

  8. 【leetcode】Merge Intervals(hard)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  9. leetcode56. Merge Intervals

    题目要求: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6 ...

  10. Leetcode: Non-overlapping Intervals

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

随机推荐

  1. ICMP隐蔽隧道攻击分析与检测(四)

    • ICMP隧道攻击通讯特征和特征提取 一.ICMP Ping正常通讯特征总结 一个正常的 ping 每秒最多只会发送两个数据包,而使用 ICMP隧道的服务器在同一时间会产生大量 ICMP 数据包 正 ...

  2. DG修复:修改密码文件导致归档不应用

    问题描述:重启完备库,之后发现主备同步状态异常,mrp进程状态显示applying log,但是v$datagaurd_stats视图中查询到归档日志并没有在应用.主库切换归档,可以正常传输过来,但是 ...

  3. DG:三种模式切换

    应用归档日志方式进行数据同步 SQL> alter system set log_archive_dest_2='SERVICE=standby arch noaffirm valid_for= ...

  4. 如何在 DevOps 中进行 API 全生命周期管理?

    随着 DevOps 理念在中国企业当中的普及和发展,中国企业 DevOps 落地成熟度不断提升,根据中国信通院的数据已有近 6 成企业向全生命周期管理迈进. 而在研发全生命周期管理之中,API 管理的 ...

  5. 重学C++ (一)基础回顾

    由于C++基础非常重要,所以打算把平时重学C++的总结,抽时间上传到博客! 1.切勿乱用带符号类型和无符号类型 #include <iostream> using namespace st ...

  6. 笔记五:进程间的通信(IPC通信之共享内存)

    IPC通信 IPC通信(Inter-Process Communication) 三种: 共享内存.消息队列.信号灯 这个IPC对象,肯定是存在于内核中.而且用户空间的文件系统中有没有IPC的文件类型 ...

  7. Vue中的$set的使用 (为对象设置属性)

    data() { return { obj: { name: 'shun' } } } 对象只有name属性,通过$set给对象添加属性(三个参数,对象名,属性名, 属性) setage() { th ...

  8. 纯前端使用xlsx实现导出表格

    列表数据纯前端使用xlsx实现导出功能 基础写法 let filename = "资产导出.xlsx"; 定义导出数据 let data = [ ["第一列", ...

  9. StarCoder: 最先进的代码大模型

    关于 BigCode BigCode 是由 Hugging Face 和 ServiceNow 共同领导的开放式科学合作项目,该项目致力于开发负责任的代码大模型. StarCoder 简介 StarC ...

  10. nginx配置文件编写及日志文件相关操作

    nginx配置文件编写及日志文件相关操作 目录 nginx配置文件编写及日志文件相关操作 nginx主配置文件扩展详解 部署nginx网站 注意事项 Nginx虚拟主机 nginx配置虚拟主机的三种方 ...