栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2750 Potted Flower

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2750 Potted Flower

#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>int a[1000010];using namespace std;struct TREE{int r,l;long long rm,lm,ma;long long rmi,lmi,mi;long long sum;}t[4000040];inline void wor(int root){t[root].sum=t[root*2].sum+t[root*2+1].sum;t[root].ma=max(max(t[root*2].ma,t[root*2+1].ma),t[root*2].rm+t[1+root*2].lm);t[root].lm=max(t[root*2].lm,t[2*root].sum+t[2*root+1].lm);t[root].rm=max(t[root*2+1].rm,t[2*root+1].sum+t[2*root].rm);t[root].mi=min(min(t[root*2].mi,t[root*2+1].mi),t[root*2].rmi+t[1+root*2].lmi);t[root].lmi=min(t[root*2].lmi,t[2*root].sum+t[2*root+1].lmi);t[root].rmi=min(t[root*2+1].rmi,t[2*root+1].sum+t[2*root].rmi);}inline void build(int root,int l,int r){if(r==l){t[root].r=r;t[root].l=l;t[root].lmi=t[root].mi=t[root].rmi=a[r];t[root].sum=t[root].ma=t[root].rm=t[root].lm=a[r];return;}else{int mid=(r+l)/2;build(root*2,l,mid);build(root*2+1,mid+1,r);wor(root);t[root].l=l,t[root].r=r;return;}}inline void change(int root,int l,int r,int pos,int ver){if(l==r){t[root].sum=t[root].ma=t[root].lm=t[root].rm=ver;t[root].lmi=t[root].rmi=t[root].mi=ver;return;}int mid=(l+r)/2;if(pos<=mid)change(root*2,l,mid,pos,ver);elsechange(root*2+1,mid+1,r,pos,ver);wor(root);}int main(){int n,nq;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);build(1,1,n);scanf("%d",&nq);int aa,bb;for(int i=1;i<=nq;i++){scanf("%d%d",&aa,&bb);change(1,1,n,aa,bb);if(t[1].ma!=t[1].sum){cout<<max(t[1].ma,t[1].sum-t[1].mi)<<endl;}else{cout<<t[1].sum-t[1].mi<<endl;}}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/363967.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号