简要题意

给定 \(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. VideoPipe可视化视频结构化框架更新总结(2023-3-30)

    项目地址:https://github.com/sherlockchou86/video_pipe_c 往期文章:https://www.cnblogs.com/xiaozhi_5638/p/1696 ...

  2. 第三章3.1HTML技术与CSS技术

    web中的html以及css: html(超文本标记语言:Hyper Text Markup Language):用于描述网页的一种语言: 通常其根标签使用html标签:使用尖括号表示:<htm ...

  3. How to implement UDP protocal

    Server implementation Open a socket on the server that listens to the UDP requests. (I've chosen 888 ...

  4. 记一次 .NET 某设备监控系统 死锁分析

    一:背景 1. 讲故事 上周看了一位训练营朋友的dump,据朋友说他的程序卡死了,看完之后发现是一例经典的死锁问题,蛮有意思,这个案例算是学习 .NET高级调试 入门级的案例,这里和大家分享一下. 二 ...

  5. socket与struct实战应用(传输文件)

    服务端 需求:制作一个可以接收文件的服务,操作客户端往服务端传输文件 服务端代码 import struct import socket import json import os # 1. 先起动服 ...

  6. 研发运维双管齐下!Seal AppManager的正确打开方式

    新一代应用统一部署管理平台 Seal AppManager 采用平台工程的理念,通过降低基础设施操作的复杂度为研发和运维团队提供易用.一致的应用管理和部署体验.Seal AppManager 帮助研发 ...

  7. 基于Switching的 恒虚警率检测算法

    转发和使用请注明来源,以下为本人精心整理,还请尊重本人劳动成果与产权!由于本人现有知识和能力有限,如存在错误之处请指正!下面为正文内容: 1.S-CFAR检测算法(Switching,开关CFAR) ...

  8. 【机器学习与深度学习理论要点】20. 什么是激活函数,为什么要用激活函数,常见的激活函数和特点,softmax函数

    1)什么是激活函数,为什么要用激活函数? 激活函数,指神经网络中将输入信号的总和转换为输出信号的函数,激活函数将多层感知机输出转换为非线性,使得神经网络可以任意逼近任何非线性函数,这样神经网络就可以应 ...

  9. Django的message组件(源码分析)

    Django的Message组件(源码分析) 1. 配置 # MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackS ...

  10. 记一次 .NET 某车零件MES系统 登录异常分析

    一:背景 1. 讲故事 这个案例有点特殊,以前dump分析都是和软件工程师打交道,这次和非业内人士交流,隔行如隔山,从指导dump怎么抓到问题解决,需要一个强大的耐心. 前几天有位朋友在微信上找到我, ...