(简单) 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张海报,海报 ...
随机推荐
- JdbcTemplate学习笔记
JdbcTemplate学习笔记 1.使用JdbcTemplate的execute()方法执行SQL语句 Java 代码 jdbcTemplate.execute("CREATE TABLE ...
- Hibernate 系列教程9-自关联
自关联:本质还是原来双向一对多,原来要配置两个类,现在全部都配置在一个类里面 Employee public class Employee { private Long id; private Str ...
- HDU5907 Find Q 数学
题目大意:求当前串中只含q的连续子串的个数 题目思路:水题,但要注意的是计算过程中可能超int范围; #include<iostream> #include<algorithm> ...
- Flexigrid的API
基本设定 width table的长度(default:auto) height table的宽度(default:200) striped 表格的线的表示(default:true) nov ...
- UVALive 2521 Game Prediction 题解
这个我上来把题目理解错了,我以为所有人的牌都是一样的,感觉这个题太麻烦了吧,而且题目样例过不去啊……后来发现理解错了,给出的数据是他一个人的数据,就是让我们求他一定能赢的轮数,所有的牌是固定的(1 - ...
- struts2+ajax实现异步验证实现
由于老师布置作业的需要,在添加管理员的时候,要实现验证添加的管理员的用户名是否在数据库中已经存在,然后再客户端给用户一个提示.我首先想到的就是利用ajax实现异步验证技术,由于利用的ssh框架,所以在 ...
- swift(2)元祖(Tuple)
let somePoint = (, ) switch somePoint { , ): // 位于远点 println("(0, 0) is at the origin") ): ...
- 转:Eclipse Debug 界面应用详解——Eclipse Debug不为人知的秘密
今天浏览csdn,发现一文详细的描述了Eclipse Debug中的各个知识点,非常详尽!特此记录. Eclipse Debug不为人知的秘密 http://blog.csdn.net/mgoann/ ...
- 5V与3.3V器件电平转换
源:5V与3.3V器件电平转换 当你使用3.3V的单片机的时候,电平转换就在所难免了,经常会遇到3.3转5V或者5V转3.3V的情况,这里介绍一个简单的电路,他可以实现两个电平的相互转换(注意是相互哦 ...
- 关于flex4 list 高度适应内容
Flex 4: Setting Spark List height to its content height How to set a Spark List height to the height ...