(简单) POJ 2750 Potted Flower,环+线段树。
Description
(Positions of potted flowers are assigned to index numbers in the range of 1 ... N. The i-th pot and the (i + 1)-th pot are consecutive for any given i (1 <= i < N), and 1st pot is next to N-th pot in addition.)

The board chairman informed the little cat to construct "ONE arc-style cane-chair" for tourists having a rest, and the sum of attractive values of the flowers beside the cane-chair should be as large as possible. You should notice that a cane-chair cannot be a total circle, so the number of flowers beside the cane-chair may be 1, 2, ..., N - 1, but cannot be N. In the above example, if we construct a cane-chair in the position of that red-dashed-arc, we will have the sum of 3+(-2)+1+2=4, which is the largest among all possible constructions.
Unluckily, some booted cats always make trouble for the little cat, by changing some potted flowers to others. The intelligence agency of little cat has caught up all the M instruments of booted cats' action. Each instrument is in the form of "A B", which means changing the A-th potted flowered with a new one whose attractive value equals to B. You have to report the new "maximal sum" after each instruction.
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月16日 星期四 19时07分04秒
// File Name : 2750.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; #define lc (po<<1)
#define rc ((po<<1)|1)
#define lson L,M,lc
#define rson M+1,R,rc int LN[MaxN<<],RN[MaxN<<],BIT[MaxN<<],SUM[MaxN<<];
int ln[MaxN<<],rn[MaxN<<],bit[MaxN<<];
int minn[MaxN<<]; void pushUP(int po)
{
SUM[po]=SUM[lc]+SUM[rc]; minn[po]=min(minn[lc],minn[rc]); BIT[po]=max(BIT[lc],BIT[rc]);
BIT[po]=max(BIT[po],max(SUM[lc]+LN[rc],SUM[rc]+RN[lc]));
BIT[po]=max(BIT[po],LN[rc]+RN[lc]); LN[po]=max(LN[lc],SUM[lc]+LN[rc]);
RN[po]=max(RN[rc],SUM[rc]+RN[lc]); bit[po]=min(bit[lc],bit[rc]);
bit[po]=min(bit[po],min(SUM[lc]+ln[rc],SUM[rc]+rn[lc]));
bit[po]=min(bit[po],ln[rc]+rn[lc]); ln[po]=min(ln[lc],SUM[lc]+ln[rc]);
rn[po]=min(rn[rc],SUM[rc]+rn[lc]);
} void update(int up,int ut,int L,int R,int po)
{
if(L==R)
{
SUM[po]=BIT[po]=LN[po]=RN[po]=ut;
bit[po]=ln[po]=rn[po]=ut;
minn[po]=ut;
return;
} int M=(L+R)>>; if(up<=M)
update(up,ut,lson);
else
update(up,ut,rson); pushUP(po);
} int num[MaxN]; void build(int L,int R,int po)
{
if(L==R)
{
LN[po]=RN[po]=BIT[po]=SUM[po]=num[L];
ln[po]=rn[po]=bit[po]=num[L];
minn[po]=num[L];
return;
} int M=(L+R)>>; build(lson);
build(rson); pushUP(po);
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int N;
int ans; scanf("%d",&N); for(int i=;i<=N;++i)
scanf("%d",&num[i]); build(,N,); int M,a,b; scanf("%d",&M); while(M--)
{
scanf("%d %d",&a,&b); update(a,b,,N,); ans=max(BIT[],SUM[]-bit[]); if(ans==SUM[])
ans-=minn[]; printf("%d\n",ans);
} return ;
}
(简单) POJ 2750 Potted Flower,环+线段树。的更多相关文章
- POJ 2750 Potted Flower(线段树的区间合并)
点我看题目链接 题意 : 很多花盆组成的圆圈,每个花盆都有一个值,给你两个数a,b代表a位置原来的数换成b,然后让你从圈里找出连续的各花盆之和,要求最大的. 思路 :这个题比较那啥,差不多可以用DP的 ...
- 【POJ 2750】 Potted Flower(线段树套dp)
[POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4566 ...
- POJ 2750 Potted Flower (线段树区间合并)
开始懵逼找不到解法,看了网上大牛们的题解才发现是区间合并... 给你n个数形成一个数列环,然后每次进行一个点的修改,并输出这个数列的最大区间和(注意是环,并且区间最大只有n-1个数) 其实只需要维护 ...
- POJ.2750.Potted Flower(线段树 最大环状子段和)
题目链接 /* 13904K 532ms 最大 环状 子段和有两种情况,比如对于a1,a2,a3,a4,a5 一是两个端点都取,如a4,a5,a1,a2,那就是所有数的和减去不选的,即可以计算总和减最 ...
- POJ 2750 Potted Flower(线段树+dp)
题目链接 虽然是看的别的人思路,但是做出来还是挺高兴的. 首先求环上最大字段和,而且不能是含有全部元素.本来我的想法是n个元素变为2*n个元素那样做的,这样并不好弄.实际可以求出最小值,总和-最小,就 ...
- POJ 2750 Potted Flower
Potted Flower Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3872 Accepted: 1446 Des ...
- POJ 2750 Potted Flower (单点改动求线段树上最大子序列和)
题目大意: 在一个序列上每次改动一个值,然后求出它的最大的子序列和. 思路分析: 首先我们不考虑不成环的问题.那就是直接求每一个区间的最大值就好了. 可是此处成环,那么看一下以下例子. 5 1 -2 ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
随机推荐
- html屏蔽右键、禁止复制与禁止查看源代码
<script> function doNothing(){ window.event.returnValue=false; return false; } </script> ...
- nagios安装全过程
Nagios是一个用来监控主机.服务和网络的开放源码软件,可以在发生故障时发送报警短信和邮件,只要Nagios监控的对象发生故障,系统就会自动发送短信到手机上.所以应用十分广泛. Nagios is ...
- 浅谈C# 多态的魅力(虚方法,抽象,接口实现)
前言:我们都知道面向对象的三大特性:封装,继承,多态.封装和继承对于初学者而言比较好理解,但要理解多态,尤其是深入理解,初学者往往存在有很多困惑,为什么这样就可以?有时候感觉很不可思议,由此,面向对象 ...
- BootStrap详解之(一)
一.BootStrap简介 BootStrap是一个用来构建网站前段框架的一个插件.无论你是想构建应用程序.博客还是CMS网站,Bootstrap都特别的使用,只要你想得到,它就能行.Bootstra ...
- 使用print2flash开发在线文档
www.print2flash.com 命令行调用: A:\Program Files (x86)\Print2Flash3>p2fServer.exe a.pdf a.swf
- AVR之BOOTLOADER技术详解(转)
源:http://blog.csdn.net/zhenhua10/article/details/6442412 ATmega128具备引导加载支持的用户程序自编程功能(In-System Progr ...
- C#入门经典(3-窗体应用程序-第二章要点)
新建一个窗体用用程序,拖一个按钮,加事件和Text属性.打开Form1Designer.cs.
- div+css与table布局
1:速度和加载方式方面的区别 div 的加载方式是即读即加载,遇到 <div> 没有遇到 </div> 的时候一样加载 div 中的内容,读多少加载多少:table 的加载方式 ...
- Hibernate分页查询小结
通常使用的Hibernate通常是三种:hql查询,QBC查询和QBE查询: 1.QBE(Qurey By Example)检索方式 QBE 是最简单的,但是功能也是最弱的,QBE的功能不是特别强大, ...
- make[1]: *** [/workopenwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_nnnnn] Error 2 make[1]: Leaving directory `/work/openwrt/trunk' make: *** [world]
主要原因是编译时未连上网,编译时需要下载些插件,连接网后,重启下系统再编译下.