简要题意

给定 \(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. CISCN2021-第十四届全国大学生信息安全竞赛-WriteUp

    WriteUp - Maple_root -CISCN2021 总结 总得分:3400 总排名:203 赛区排名:21 第一次认真参加正式的CTF,24+3小时的脑血栓比赛时长,收获还是很多的. 开卷 ...

  2. 来自jackson的灵魂一击:@ControllerAdvice就能保证万无一失吗?

    前几天写了篇关于fastjson的文章,<fastjson很好,但不适合我>.里面探讨到关于对象循环引用的序列化问题.作为spring序列化的最大竞品,在讨论fastjson的时候肯定要对 ...

  3. docker方式实现minio数据持久化离线安装

    保存镜像 root@hello:~# docker pull minio/minio Using default tag: latest latest: Pulling from minio/mini ...

  4. Django笔记十七之group by 分组用法总结

    本文首发于微信公众号:Hunter后端 原文链接:Django笔记十七之group by 分组用法总结 这篇笔记介绍 Django 里面 model 的 group by 对应的一些操作. 用到的 M ...

  5. SpringBoot 整合 JDBC 实例

    0.数据库表 CREATE DATABASE springboot; USE springboot; CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_ ...

  6. day01-Redis入门

    Redis入门 1.初始Redis 1.1认识NoSQL SQL(关系型数据库) NoSQL(非关系型数据库) 数据结构 结构化(Structured) 非结构化 数据关联 关联的(Relationa ...

  7. 解决CKEditor中img标签自动添加style样式的问题-禁止自动设置width和height 帝国cms编辑器图片自动加宽高

    在使用CKEditor的过程中发现,每次上传或添加图片的时候,总会自动给img标签添加width和height的style内联样式.由于网站本身对图片有进行自适应处理(添加了自适应的CSS),所以im ...

  8. Linux shell和环境变量

    环境变量 存储有关shell会话和工作环境信息:允许在内存中存储数据. 注意什么时候要用$ 什么时候不用$:用到变量,需要$;操作变量,不需要$.printenv除外 分为两类: 全局变量:对shel ...

  9. DeFi4-稳定币

    稳定币--稳定 是一个相对的度量指标 波动性,收益率标准差 在一个时间段内最大跌幅 Fiat,例如: 欧元.英镑的波动率为6-12% (波动本身并不能反映价格的范围 稳定币 vs 锚定币 稳定币类型 ...

  10. NPM 实用命令与快捷方式

    在 JavaScript 中,无论是新手还是专家都可能在命令行中使用过 NPM.在本篇文章中,我将会整理超实用的 NPM 命令.快捷方式及技巧,帮助 JavaScript 开发人员提高生产力和效率. ...