当前位置:网站首页>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
边栏推荐
- ACM getting started Day1
- leetcode刷题:二叉树16(路径总和)
- No matter how busy you are, you can't forget safety
- How to select the Block Editor? Impression notes verse, notation, flowus
- C langue OJ obtenir PE, ACM démarrer OJ
- C - sequential structure
- 四万字长文说operator new & operator delete
- Wildcard selector
- Thread pool parameters and reasonable settings
- How to safely and quickly migrate from CentOS to openeuler
猜你喜欢
深度学习 卷积神经网络(CNN)基础
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
What do software test engineers do? How about the prospect of treatment?
Parler de threadlocal insecurerandom
通过POI追加数据到excel中小案例
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
redis集群模拟消息队列
城链科技数字化创新战略峰会圆满召开
浅浅的谈一下ThreadLocalInsecureRandom
四万字长文说operator new & operator delete
随机推荐
Flume series: interceptor filtering data
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
DP:树DP
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
Is it safe to open a mobile stock account? Is it reliable?
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
Using repositoryprovider to simplify the value passing of parent-child components
What is the function of okcc call center
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
股票开户哪里好?网上客户经理开户安全吗
C language OJ gets PE, OJ of ACM introduction~
MySql的root密码忘记该怎么找回
Debezium series: parsing the default value character set
Gstreamer中的task
ICTCLAS用的字Lucene4.9捆绑
建议收藏,我的腾讯Android面试经历分享
Let's talk about threadlocalinsecurerandom
C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
完爆面试官,一线互联网企业高级Android工程师面试题大全
力扣 729. 我的日程安排表 I