当前位置:网站首页>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
边栏推荐
- 多分支结构
- Is the education of caiqiantang reliable and safe?
- 【硬核干货】数据分析哪家强?选Pandas还是选SQL
- How about testing outsourcing companies?
- Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
- What do software test engineers do? How about the prospect of treatment?
- 深度學習 卷積神經網絡(CNN)基礎
- Concept and syntax of function
- 字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
- [hard core dry goods] which company is better in data analysis? Choose pandas or SQL
猜你喜欢
What do software test engineers do? How about the prospect of treatment?
The city chain technology Digital Innovation Strategy Summit was successfully held
城链科技数字化创新战略峰会圆满召开
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
Recommended collection, my Tencent Android interview experience sharing
ACM getting started Day1
Let's talk about threadlocalinsecurerandom
Reinforcement learning - learning notes 4 | actor critical
如何安全快速地从 Centos迁移到openEuler
JVMRandom不可设置种子|问题追溯|源码追溯
随机推荐
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
Reptile exercises (II)
Jvmrandom cannot set seeds | problem tracing | source code tracing
Necessary skills for interview in large factories, 2022android will not die, I will not fall
四万字长文说operator new & operator delete
14. Users, groups, and permissions (14)
[untitled]
期货如何网上开户?安不安全?
Recommended collection, my Tencent Android interview experience sharing
Android interview classic, 2022 Android interview written examination summary
Fundamentals of deep learning convolutional neural network (CNN)
Flume series: interceptor filtering data
《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
秋招字节面试官问你还有什么问题?其实你已经踩雷了
JVMRandom不可设置种子|问题追溯|源码追溯
Common - Hero Minesweeper
Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
How to apply smart contracts more wisely in 2022?
打新债在哪里操作开户是更安全可靠的呢