当前位置:网站首页>BZOJ 3747 POI2015 Kinoman 段树
BZOJ 3747 POI2015 Kinoman 段树
2022-07-05 19:53:00 【全栈程序员站长】
大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。
标题效果:有m点,每个点都有一个权值。现在我们有这个m为点的长度n该序列,寻求区间,它仅出现一次在正确的点区间内值和最大
想了很久,甚至神标题,奔说是水的问题……我醉了
枚举左点 对于每个请求留点右键点 树维护最大值
考虑每一个数对答案的贡献 记录一个数组next表示这个位置上的点下一次出现的位置 那么这个点贡献的作用范围就是[i,next[i]-1] 假设没有next就是[i,n]
于是我们先把全部第一个出现的数对答案的贡献增加线段树 然后从左到右扫一遍 每次统计完答案之后把i对答案的贡献去除 然后把next[i]对答案的贡献增加线段树
这常数我也是醉了……速度倒数第二啥的 正解一定不是这种……
此外POI2015是我穿错年代了?
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 1001001
using namespace std;
struct Segtree{
Segtree *ls,*rs;
long long num,mark;
void Build_Tree(int x,int y);
void Update(int x,int y,int l,int r,long long val);
long long Get_Ans(int x,int y,int l,int r);
}*root=new Segtree,mempool[M<<1],*C=mempool;
int n,m;
int a[M],w[M],next[M],last[M];
bool v[M];
long long ans;
void Segtree :: Build_Tree(int x,int y)
{
int mid=x+y>>1;
num=0;mark=0;
if(x==y) return ;
ls=C++;rs=C++;
ls->Build_Tree(x,mid);
rs->Build_Tree(mid+1,y);
}
void Segtree :: Update(int x,int y,int l,int r,long long val)
{
int mid=x+y>>1;
if(x==l&&y==r)
{
num+=val;
mark+=val;
return ;
}
if(mark)
{
ls->num+=mark;
rs->num+=mark;
ls->mark+=mark;
rs->mark+=mark;
mark=0;
}
if(r<=mid) ls->Update(x,mid,l,r,val);
else if(l>mid) rs->Update(mid+1,y,l,r,val);
else ls->Update(x,mid,l,mid,val),rs->Update(mid+1,y,mid+1,r,val);
num=max(ls->num,rs->num);
}
long long Segtree :: Get_Ans(int x,int y,int l,int r)
{
int mid=x+y>>1;
if(x==l&&y==r)
return num;
if(mark)
{
ls->num+=mark;
rs->num+=mark;
ls->mark+=mark;
rs->mark+=mark;
mark=0;
}
if(r<=mid) return ls->Get_Ans(x,mid,l,r);
if(l> mid) return rs->Get_Ans(mid+1,y,l,r);
return max( ls->Get_Ans(x,mid,l,mid) , rs->Get_Ans(mid+1,y,mid+1,r) );
}
int main()
{
int i;
cin>>n>>m;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=m;i++)
scanf("%d",&w[i]);
for(i=1;i<=n;i++)
{
if(last[a[i]])
next[last[a[i]]]=i;
else
v[i]=1;
last[a[i]]=i;
}
root->Build_Tree(1,n);
for(i=1;i<=n;i++)
if(v[i])
root->Update(1,n,i,next[i]?next[i]-1:n,w[a[i]]);
for(i=1;i<=n;i++)
{
ans=max(ans, root->Get_Ans(1,n,i,n) );
root->Update(1,n,i,next[i]?next[i]-1:n,-w[a[i]]);
if(next[i])
root->Update(1,n,next[i],next[next[i]]?next[next[i]]-1:n,w[a[next[i]]]);
}
cout<<ans<<endl;
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117735.html原文链接:https://javaforall.cn
边栏推荐
- C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
- okcc呼叫中心有什么作用
- Reinforcement learning - learning notes 4 | actor critical
- 【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
- [untitled]
- 太牛了,看这篇足矣了
- IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
- Where is the operation of new bonds? Is it safer and more reliable to open an account
- Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
- 字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
猜你喜欢
![[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp](/img/32/738df44b6005fd84b4a9037464e61e.jpg)
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp

leetcode刷题:二叉树11(平衡二叉树)

Go language | 03 array, pointer, slice usage

Force buckle 729 My schedule I

深度学习 卷积神经网络(CNN)基础

CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)

建议收藏,我的腾讯Android面试经历分享

【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
![[AI framework basic technology] automatic derivation mechanism (autograd)](/img/9c/a5713def131dc7643cc19b3839ff0c.png)
[AI framework basic technology] automatic derivation mechanism (autograd)
PHP uses ueditor to upload pictures and add watermarks
随机推荐
No matter how busy you are, you can't forget safety
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Which securities company is better and which platform is safer for mobile account opening
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
C application interface development foundation - form control (5) - grouping control
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
完爆面试官,一线互联网企业高级Android工程师面试题大全
Relationship between floating elements and parent and brother boxes
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
信息/数据
2023年深圳市绿色低碳产业扶持计划申报指南
建议收藏,我的腾讯Android面试经历分享
淺淺的談一下ThreadLocalInsecureRandom
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
图嵌入Graph embedding学习笔记
Multi branch structure
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
众昂矿业:2022年全球萤石行业市场供给现状分析