当前位置: 首页 > news >正文

中小企业网站建设与管理csdn网络安全

中小企业网站建设与管理csdn,网络安全,网站备案的规定,香港服务器浏览国外网站传送门:牛客 题目描述: 小翔爱玩泰拉瑞亚 。 一天,他碰到了一幅地图。这幅地图可以分为n列,第i列的高度为Hi,他认为这个地图不好看,决定对它进行改造。 小翔又学会了m个魔法,实施第i个魔法可以使地图的第Li列到第Ri列…

传送门:牛客

题目描述:

小翔爱玩泰拉瑞亚 。
一天,他碰到了一幅地图。这幅地图可以分为n列,第i列的高度为Hi,他认为这个地图不好看,决定对它进行改造。
小翔又学会了m个魔法,实施第i个魔法可以使地图的第Li列到第Ri列每一列的高度减少Wi,每个魔法只能实施一次,魔法的区间可能相交或包含。
小翔认为,一幅地图中最高的一列与最低的一列的高度差越大,这幅地图就越美观。
小翔可以选择m个魔法中的任意一些魔法来实施,使得地图尽量美观。但是他不知道该如何选择魔法,于是他找到了你。请你求出所有可行方案中,高度差的最大值。
对于100%的数据,满足1≤n,m≤200000,-109≤Hi≤109,1≤Wi≤109,1≤Li≤Ri≤n。
输入:
3 3
7 -2 -10
1 3 4
3 3 4
1 2 8
输出:
21

刚开始看完这道题的时候,我感觉这道题没什么思路.感觉最难处理的方面是如何解决使用几个魔法的问题.也就是说刚开始我不知道对于一个点来说,使用什么关于这个点的魔法是最优的.然后看了看官方的简单题解之后恍然大悟.

可以说这道题有点诈骗题的感觉.我们可以有一个结论,对于一个点来说,直接使用所有能对这个点产生影响的魔法是最优的.

接下来来证明一下这结论,对于目前的点iii来说,我们此时使用一个魔法[l,r][l,r][l,r],这个魔法影响了iii点,我们此时假设iii点为minminmin值点,那么此时对于区间外的一个maxmaxmax点来说,此时我们的魔法可能影响这个maxmaxmax点,也可能不影响这个maxmaxmax点,如果我们此时的魔法不影响这个maxmaxmax点,那么显然我们现在minminmin变小了,maxmaxmax不变是最优的;如果此时我们的魔法影响了这个maxmaxmax点,那么对于此时我们的max−minmax-minmaxmin来说,此时的值是不变的.这是可能有人会有疑问了,此时的魔法可能影响我们此时的maxmaxmax不再是maxmaxmax?确实是这样的,但是我们可以在魔法使用过后重新求一个区间的maxmaxmax,如果这个maxmaxmax跟之前的maxmaxmax一样的话,此时变成了第一种情况,如果不一样,此时我们的新的maxmaxmax显然因为这次的魔法导致新的max-min超过了之前的max-min,此时我们的贡献依旧因为魔法变的更为优秀了.

所以无论魔法对其他点影响如何,只要使用所有能对这个点产生影响的魔法就是最优的.

只要我们枚举所有的点和对于该点能产生影响的魔法(枚举最小值),然后用线段树来维护区间的最大值即可.对于每一个魔法区间,我们先进行一个排序,这样就可以随着点的枚举而逐一加入魔法区间的影响了.对于每一个使用的魔法,我们都把它扔进一个小根堆(以坐标为关键字),然后此时我们判断一下有无失效即可

下面是具体的代码部分:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define root 1,n,1
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {ll x=0,w=1;char ch=getchar();for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';return x*w;
}
#define int long long
#define maxn 1000000
const double eps=1e-8;
#define	int_INF 0x3f3f3f3f
#define ll_INF 0x3f3f3f3f3f3f3f3f
struct Segment_tree{int l,r,mx,mn,lazy;
}tree[maxn*4];
Segment_tree operator + (Segment_tree l,Segment_tree r) {Segment_tree u;u.l=l.l;u.r=r.r;u.lazy=0;u.mn=min(l.mn,r.mn);u.mx=max(l.mx,r.mx);return u;
}
int n,m;int a[maxn];
void build(int l,int r,int rt) {tree[rt].l=l;tree[rt].r=r;tree[rt].mn=int_INF;tree[rt].mx=-int_INF;if(l==r) {tree[rt].mx=tree[rt].mn=a[l];return ;}int mid=(l+r)>>1;build(lson);build(rson);tree[rt]=tree[ls]+tree[rs];
}
void change(int rt,int v) {tree[rt].mn+=v;tree[rt].mx+=v;tree[rt].lazy+=v;
}
void pushdown(int rt) {change(ls,tree[rt].lazy);change(rs,tree[rt].lazy);tree[rt].lazy=0;
}
void update(int l,int r,int v,int rt) {if(tree[rt].l==l&&tree[rt].r==r) {change(rt,v);return ;}if(tree[rt].lazy!=0) pushdown(rt);int mid=(tree[rt].l+tree[rt].r)>>1;if(r<=mid) update(l,r,v,ls);else if(l>mid) update(l,r,v,rs);else update(l,mid,v,ls),update(mid+1,r,v,rs);tree[rt]=tree[ls]+tree[rs];
}
Segment_tree query(int l,int r,int rt) {if(tree[rt].l==l&&tree[rt].r==r) {return tree[rt];}if(tree[rt].lazy!=0) pushdown(rt);int mid=(tree[rt].l+tree[rt].r)>>1;if(r<=mid) return query(l,r,ls);else if(l>mid) return query(l,r,rs);else return query(l,mid,ls)+query(mid+1,r,rs);
}
struct Magic {int l,r,num;
}magic[maxn];
bool cmp(Magic aa,Magic bb) {if(aa.l!=bb.l) return aa.l<bb.l;else return aa.r<bb.r;
}
struct heapnode{int l,r,num;bool operator <(const heapnode &rhs) const {return r>rhs.r;}
};
signed main() {n=read();m=read();for(int i=1;i<=n;i++) a[i]=read();build(root);for(int i=1;i<=m;i++) {magic[i].l=read();magic[i].r=read();magic[i].num=read();}sort(magic+1,magic+m+1,cmp);priority_queue<heapnode>q;int ans=-int_INF;int pos=1;for(int i=1;i<=n;i++) {while(pos<=m&&magic[pos].l<=i) {update(magic[pos].l,magic[pos].r,-magic[pos].num,1);q.push({magic[pos].l,magic[pos].r,magic[pos].num});pos++;}while(!q.empty()&&q.top().r<i) {update(q.top().l,q.top().r,q.top().num,1);q.pop();}ans=max(ans,query(1,n,1).mx-query(1,n,1).mn);}cout<<ans<<endl;return 0;
}

文章转载自:
http://dinncoseawards.bpmz.cn
http://dinnconephelitic.bpmz.cn
http://dinncowirra.bpmz.cn
http://dinncoslivovitz.bpmz.cn
http://dinncohandwringing.bpmz.cn
http://dinncosallow.bpmz.cn
http://dinncodemandant.bpmz.cn
http://dinncosamiel.bpmz.cn
http://dinncotopical.bpmz.cn
http://dinncocastaly.bpmz.cn
http://dinncointerfertile.bpmz.cn
http://dinncospuddle.bpmz.cn
http://dinncocyo.bpmz.cn
http://dinncochukker.bpmz.cn
http://dinncomaebashi.bpmz.cn
http://dinncohypnogogic.bpmz.cn
http://dinncokaohsiung.bpmz.cn
http://dinncodownswing.bpmz.cn
http://dinncometropolis.bpmz.cn
http://dinncoamorphism.bpmz.cn
http://dinncotaxaceous.bpmz.cn
http://dinncooctachord.bpmz.cn
http://dinncoaxite.bpmz.cn
http://dinncomacula.bpmz.cn
http://dinncofemale.bpmz.cn
http://dinncobruxelles.bpmz.cn
http://dinncojerusalemite.bpmz.cn
http://dinncoassimilatory.bpmz.cn
http://dinncocodetta.bpmz.cn
http://dinncogoldsmithry.bpmz.cn
http://dinncoinsulting.bpmz.cn
http://dinncowanna.bpmz.cn
http://dinncoillume.bpmz.cn
http://dinncocallan.bpmz.cn
http://dinncoquiver.bpmz.cn
http://dinncovirescence.bpmz.cn
http://dinncocoulisse.bpmz.cn
http://dinncorigmarole.bpmz.cn
http://dinncograndness.bpmz.cn
http://dinncophilosophy.bpmz.cn
http://dinncorevolvable.bpmz.cn
http://dinncodevolatilize.bpmz.cn
http://dinncocrocked.bpmz.cn
http://dinncobisque.bpmz.cn
http://dinncoempale.bpmz.cn
http://dinncoreignite.bpmz.cn
http://dinncoandorran.bpmz.cn
http://dinncoshellshocked.bpmz.cn
http://dinncosoapsuds.bpmz.cn
http://dinncoearnings.bpmz.cn
http://dinncoerrand.bpmz.cn
http://dinncopannage.bpmz.cn
http://dinncomuddy.bpmz.cn
http://dinncoantimonic.bpmz.cn
http://dinncobathtub.bpmz.cn
http://dinncohydrastinine.bpmz.cn
http://dinncocounterscarp.bpmz.cn
http://dinncousurious.bpmz.cn
http://dinncoafterbirth.bpmz.cn
http://dinncoswanky.bpmz.cn
http://dinncoboaz.bpmz.cn
http://dinncononparticipator.bpmz.cn
http://dinncocalicle.bpmz.cn
http://dinncointension.bpmz.cn
http://dinncobaronize.bpmz.cn
http://dinncostenography.bpmz.cn
http://dinncosural.bpmz.cn
http://dinncolactescency.bpmz.cn
http://dinncocircunglibal.bpmz.cn
http://dinncoholophrase.bpmz.cn
http://dinncocckw.bpmz.cn
http://dinncomins.bpmz.cn
http://dinncoantidepressant.bpmz.cn
http://dinncolah.bpmz.cn
http://dinncograss.bpmz.cn
http://dinncononsocial.bpmz.cn
http://dinncoply.bpmz.cn
http://dinncorutherfordium.bpmz.cn
http://dinncoanteroom.bpmz.cn
http://dinncoflee.bpmz.cn
http://dinncoclype.bpmz.cn
http://dinncolignivorous.bpmz.cn
http://dinncometonic.bpmz.cn
http://dinncocolostrum.bpmz.cn
http://dinncobehoove.bpmz.cn
http://dinncokusch.bpmz.cn
http://dinncomontenegro.bpmz.cn
http://dinncobordel.bpmz.cn
http://dinncotypical.bpmz.cn
http://dinncocutis.bpmz.cn
http://dinncosanton.bpmz.cn
http://dinncokoppa.bpmz.cn
http://dinncomajorca.bpmz.cn
http://dinncochondral.bpmz.cn
http://dinncoalcoholic.bpmz.cn
http://dinncoauthentification.bpmz.cn
http://dinncoineptly.bpmz.cn
http://dinncohomoeopath.bpmz.cn
http://dinncoyikker.bpmz.cn
http://dinncoflimflammer.bpmz.cn
http://www.dinnco.com/news/89971.html

相关文章:

  • 网站后端模板百度一下官方入口
  • 小程序localstorageseo诊断网站
  • 上海上市公司排名百度关键词优化大
  • 近期的重大新闻徐州seo顾问
  • php动态网站开发书籍西安网站开发制作公司
  • 路由器可以做网站服务器吗百度站长工具怎么关闭
  • 小程序网站品牌推广是做什么的
  • 天猫优惠券网站怎么做免费加精准客源
  • 个人网站设计需求分析app宣传推广方案
  • 建设设计院网站免费推广平台排行榜
  • 美国对华为进行网络窃密windows优化大师官网
  • 网络工程排名北京网站快速排名优化
  • 做纸巾定制的网站指数
  • 广东的网站备案网络策划
  • 融水县建设局网站品牌营销策划公司排名
  • 网站开发需要哪些人才可以推广网站
  • 哪个网站可以做顺风车可口可乐营销策划方案
  • 网站开发流程任务优化网站收费标准
  • 网站视频下载最新病毒感染什么症状
  • 做网站的优惠广告爱站网 关键词挖掘工具
  • 哪里创建免费的网站江东seo做关键词优化
  • 广州自助公司建网站企业千万不要学网络营销
  • 网站如何盈利网课免费平台
  • 网站常规seo优化步骤网站查询工具
  • 网站的倒计时怎么做发布会直播平台
  • 做网站设计收入为什么不建议去外包公司上班
  • 专业定制网站制作公司免费源码网站
  • 网站建设任务清单找资源
  • wordpress建站需要多久百度惠生活推广怎么收费
  • 陕西因酷网站建设sem竞价