题目描述

You are given $ n $ intervals and $ m $ points on the number line. The $ i $ -th intervals covers coordinates $ [l_i,r_i] $ and the $ i $ -th point is on coordinate $ i $ and has coefficient $ p_i $ .

Initially, all points are not activated. You should choose a subset of the $ m $ points to activate. For each of $ n $ interval, we define its cost as:

  • $ 0 $ , if there are no activated points in the interval;
  • the coefficient of the activated point with the largest coordinate within it, otherwise.

Your task is to maximize the sum of the costs of all intervals by choosing which points to activate.

$ 1 \le t \le 10^5,1 \le n \le 10^6, 1 \le m \le 10^6,1 \le l_i \le r_i \le m,0 \le p_i \le 10^9 $

\(\sum n,\sum m\le 10^6\)

一个非常显然的 dp,定义 \(dp_i\) 前 \(i\) 个数,选择了 \(i\) 的代价。那么枚举上一个数选在哪里,计算一下中间区间的贡献就行了。复杂度 \(O(n^2)\)

这个过程是可以用分块凸包维护,复杂度 \(O(n\sqrt n)\)

也可以用 KTT 维护,复杂度 \(O(log^3n)\)

然后讲官方做法。反过来,考虑一个 \(dp_i\) 对后面的 dp 的贡献。那么发现可以维护一个 \(h\),此时 \(dp_j=dp_i+h_jp_i\),同时要支持后缀加减 \(h\)。

考虑李超树,由于 \(h\) 单调不降,所以同时之前已经加入了李超树的线段不会改变。那么这些线段因为 \(h\) 改变了,线段也要改成 \(k(h+c)-b-k*c\),然后打标记下传就可以了。新增的线段直接按照 \(h\) 来加入。但是注意到要把所有跨过那个后缀的所有线段下传到两边,所以复杂度 \(O(nlog^2n)\)

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
typedef long long LL;
const LL INF=1e18;
int read()
{
char ch=getchar();
int s=0;
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')
s=s*10+ch-48,ch=getchar();
return s;
}
struct node{
int k;
LL b;
LL ask(int x)
{
return 1LL*k*x+b;
}
}tr[N<<2];
int tg[N<<2],hl[N<<2],hr[N<<2],c[N],l,r,n,m,p[N];
vector<int>g[N];
LL ans=0;
void merge(int o,int x)
{
int md=l+r>>1;
tg[o]+=x;
hl[o]+=x;
hr[o]+=x;
tr[o].b-=1LL*x*tr[o].k;
}
void pushdown(int o)
{
if(tg[o]&&(o<<1|1)<=4*m)
{
merge(o<<1,tg[o]);
merge(o<<1|1,tg[o]);
tg[o]=0;
}
}
void insert(int o,int l,int r,node x)
{
if(x.b<-1e17)
return;
pushdown(o);
int md=hl[o]==hr[o]? hl[o]:hr[o<<1];
if(x.ask(md)>tr[o].ask(md))
swap(tr[o],x);
if(x.ask(hl[o])>tr[o].ask(hl[o]))
insert(o<<1,l,md,x);
if(x.ask(hr[o])>tr[o].ask(hr[o]))
insert(o<<1|1,md+1,r,x);
}
void updtag(int o,int l,int r,int x,int y)
{
if(l>=x)
{
merge(o,y);
return;
}
int md=l+r>>1;
pushdown(o);
insert(o<<1,l,md,tr[o]);
insert(o<<1|1,md+1,r,tr[o]);
tr[o].k=0,tr[o].b=-INF;
if(md>=x)
updtag(o<<1,l,md,x,y);
updtag(o<<1|1,md+1,r,x,y);
hl[o]=hl[o<<1],hr[o]=hr[o<<1|1];
}
pair<int,LL> ask(int o,int l,int r,int x)
{
if(l==r)
return make_pair(hl[o],tr[o].ask(hl[o]));
pushdown(o);
int md=l+r>>1;
pair<int,LL>ret;
if(md>=x)
ret=ask(o<<1,l,md,x);
else
ret=ask(o<<1|1,md+1,r,x);
return make_pair(ret.first,max(ret.second,tr[o].ask(ret.first)));
}
int main()
{
int T=read();
while(T--)
{
n=read(),m=read();
p[++m]=0;
ans=0;
for(int i=1;i<=m;i++)
g[i].clear(),c[i]=0;
for(int i=1;i<=4*m;i++)
hl[i]=hr[i]=tg[i]=tr[i].k=0,tr[i].b=-INF;
for(int i=1;i<=n;i++)
{
l=read(),r=read();
g[l].push_back(r+1);
c[r+1]++;
}
for(int i=1;i<m;i++)
p[i]=read();
for(int i=1;i<=m;i++)
{
LL dp=max(0LL,ask(1,1,m,i).second);
for(int j=0;j<g[i].size();j++)
updtag(1,1,m,g[i][j],1);
updtag(1,1,m,i,-c[i]);
if(i==m)
printf("%lld\n",dp);
insert(1,1,m,(node){p[i],dp});
}
}
}

[CF1830F] The Third Grace的更多相关文章

  1. 微信小程序开发库grace vs wepy

    grace和wepy都是辅助小程序开发的开源库,本文对两者做个对比. 注:本文是作者本人的一些拙见,纯粹的技术讨论,不想引起技术信仰之争,欢迎积极.正向的讨论及建议. 如果你还不了解Grace, 请参 ...

  2. Style Lessons in Clarity and Grace (11th Edition)中文翻译

    Joseph, Williams. "Style: Lessons in Clarity and Grace." Pearson Schweiz Ag (2014). 下载地址:h ...

  3. Grace Huang 2017/1/12

    原文 Huang doesn't think of acting as pretending to be someone else.Rather,she considers it an opportu ...

  4. Grace Huang 2017/1/11

    原文 This actress becomes each character she plays Grace Huang has no interested in doing same thing y ...

  5. Grace Hopper

    葛丽丝·穆雷·霍普(英语:Grace Murray Hopper,1906年12月9日-1992年1月1日),本姓穆雷(Murray),霍普(Hopper)为夫姓,生于美国纽约州纽约市,美国海军准将及 ...

  6. Grace Hopper 葛丽丝 霍普

    Grace Murray Hopper(1906-1992), COBOL之母, Debug之母, A ship in port is safe, but that is not what ships ...

  7. ORACLE EXPIRED(GRACE)

    查询用户状态col username for a20col account_status for a20select username,account_status,LOCK_DATE,EXPIRY_ ...

  8. 编译器与Debug的传奇:Grace Murray Hopper小传

    摘要: 改变世界的程序员前辈. 来自:http://www.road2stat.com/cn/network_3c/grace_murray_hopper.html 这两天读<UNIX痛恨者手册 ...

  9. C#下IOC/依赖注入框架Grace介绍

    对依赖注入或控制反转不了解的童鞋请先自行学习一下这一设计,这里直接介绍项目和实现步骤. Grace是一个开源.轻巧.易用同时特性丰富.性能优秀的依赖注入容器框架.从这篇IOC容器评测文章找到的Grac ...

  10. Grace模式、Saint模式

    一.probe(后端探针) 探测后端,确定他们是否健康,返回的状态用req.backend.healthy核对 backend b1 { .host = "127.0.0.1"; ...

随机推荐

  1. 解密Prompt系列13. LLM Agent-指令微调方案: Toolformer & Gorilla

    上一章我们介绍了基于Prompt范式的工具调用方案,这一章介绍基于模型微调,支持任意多工具组合调用,复杂调用的方案.多工具调用核心需要解决3个问题,在哪个位置进行工具调用(where), 从众多工具中 ...

  2. 通过Scrum实现最大生产力的五种方法

    在数字化.信息化.智能化蓬勃发展的今天,敏捷开发和Scrum已成为重塑项目管理的重要方式. 敏捷是一种体现不同方法的思维方式,包括了Scrum,看板,极限编程(XP).精益开发等众多框架. Scrum ...

  3. 使用pycharm脚本发送钉钉群通知

    使用Pychon脚本发送钉钉群通知 我们可以使用钉钉的机器人助手发送群通知,只需要非常简单的配置就可以实现,而没有任何的成本. 1) 首先我们要在钉钉群里添加一个机器人助手 选择智能群助手,然后选择添 ...

  4. API接口开发管理平台--多领域企业数字化管理解决方案

    随着数字化时代的到来,企业需要进行数字化转型才能更好地适应市场需求和用户需求.而API接口则是数字化转型中的重要组成部分,可以帮助企业更好地管理信息,提高效率.本文将介绍挖数据解决方案--API接口开 ...

  5. JS深入学习笔记 - 第一章.构造函数原型与原型链

    1.构造函数和原型 1.1 概述 在典型的 OOP语言中(如Java),都存在类的概念,类就是对象的模板,对象就是类的实例,但在ES6之前,JS并没有引入类的概念. 在ES6之前,对象不是基于类创建的 ...

  6. Record -「CSP-S 2020」赛后总结

    其实这次的 CSP 暴露出来了很多问题. 比如策略上的,在 T1 花了太多的时间直接心态爆炸,后面的题只想着把暴力打满.看到 T2 只想着打暴力,根本没有沉下心来想,白白丢了一道(水)题. T3 连暴 ...

  7. Linux 安装 helm

    下载helm压缩包,地址   https://github.com/helm/helm/releases/tag/v3.10.1 选择适合自己操作系统的包 上传解压安装 1 root@calico-m ...

  8. ConcurrentHashMap底层源码分析

    ConcurrentHashMap源码底层分析 1.ConcurrentHashMap初始化 jdk8之后,ConcurrentHashMap采用了HashMap的底层结构(数据,链表,红黑树),在此 ...

  9. HTTPS相比HTTP为什么安全

    HTTPS(超文本传输协议[安全]) 1.HTTPS为什么叫安全的超文本传输协议 在HTTPS中,S是Security的意思,是安全的意思,而HTTP是超文本传输协议,这就不得不谈起HTTP在安全方面 ...

  10. 【FAQ】关于获取运动健康数据的常见问题及解答

    目录 一.Health Kit健康数据采样, 原子采样数据问题 二.Health Kit查询历史数据查询数据和返回数据不一致 三.Health Kit关于获取历史数据问题 四.调用Health Kit ...