当前位置:网站首页>Bzoj 3747 poi2015 kinoman segment tree
Bzoj 3747 poi2015 kinoman segment tree
2022-07-05 19:58:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack , I've prepared for you today Idea Registration code .
Title Effect : Yes m spot , Each point has a weight . Now we have this m Is the length of the point n This sequence , Seek the interval , It only appears once in the correct point interval and the maximum
I thought for a long time. , Even God's title , Ben said it was a water problem …… I'm drunk
Enumerate left points For each request, right click Tree maintenance maximum
Consider the contribution of each number to the answer Record an array next Indicates the position of the next occurrence of the point on this position Then the scope of contribution of this point is [i,next[i]-1] Suppose there is no next Namely [i,n]
So we first add the contribution of all the first numbers to the answer to the line segment tree Then scan it from left to right After counting the answers every time i The contribution to the answer is removed And then put next[i] The contribution to the answer increases the segment tree
I'm also drunk with this constant …… Second to last in speed The positive solution must not be like this ……
Besides POI2015 I'm wearing the wrong age ?
#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;
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117735.html Link to the original text :https://javaforall.cn
边栏推荐
- 众昂矿业:2022年全球萤石行业市场供给现状分析
- 【obs】libobs-winrt :CreateDispatcherQueueController
- 《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
- How about testing outsourcing companies?
- 使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
- 【无标题】
- Webuploader file upload drag upload progress monitoring type control upload result monitoring control
- 处理文件和目录名
- [untitled]
- Debezium series: idea integrates lexical and grammatical analysis ANTLR, and check the DDL, DML and other statements supported by debezium
猜你喜欢
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
ACM getting started Day1
Add data to excel small and medium-sized cases through poi
Necessary skills for interview in large factories, 2022android will not die, I will not fall
Xaas trap: all things serve (possible) is not what it really needs
【无标题】
That's awesome. It's enough to read this article
安卓面试宝典,2022Android面试笔试总结
How to select the Block Editor? Impression notes verse, notation, flowus
随机推荐
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
Force buckle 1200 Minimum absolute difference
Using repositoryprovider to simplify the value passing of parent-child components
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
Xaas trap: all things serve (possible) is not what it really needs
ACM getting started Day1
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
国信证券在网上开户安全吗?
SecureRandom那些事|真伪随机数
leetcode刷题:二叉树11(平衡二叉树)
MySql的root密码忘记该怎么找回
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
成功入职百度月薪35K,2022Android开发面试解答
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
Postman core function analysis - parameterization and test report
什么是pyc文件
JVMRandom不可设置种子|问题追溯|源码追溯
gst-launch的-v参数