(简单) 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张海报,海报 ...
随机推荐
- 在MyEclipse中运行tomcat报错 严重: Error starting static Resources
严重: Error starting static Resourcesjava.lang.IllegalArgumentException: Document base E:\apache-tomca ...
- 实现jsp页面显示用户登录信息,利用session保存。
这是后台代码 这是jsp代码,上面是声明,下面是获得值.
- UVA 1400 线段树
input n m 1<=n,m<=500000 a1 a2 ... an |ai|<=1e9 m行查询 每行一对a b output 对于每对a b输出区间[a,b]中最小连续和x ...
- linux视频学习3(shell和网络)
1.shell的学习. shell的种类比较多,主要有三种: /bin/sh, /bin/csh, /bin/ksh. 查看当前使用的是哪种shell : 命令env (显示当前操作系统的环境变量). ...
- 关于一些url中传递参数有空格问题
1.关于一些url中传递参数有空格问题: url.replace(/ /g, "%20") 从上面的例子中可以看到可以用:replace(/ /g, "%20" ...
- hdu1285 确定比赛名次(拓扑排序)
确定比赛名次 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- java包(package)
为了更好地组织类,java提供了包机制,用于区别类名的命名空间. 这样在不同的命名空间就可以有相同命名的类. 1 把功能相似或相关的类或接口阻止在同一个包中,方便类的查找和使用. 2 如同文件夹一样, ...
- Centos-ip配置详解
1 搭建好Centos ,我这里是CentOS-6.7-x86_64-minimal 提供一个下载地址 链接:http://pan.baidu.com/s/1nvTUTh3 密码:xewk 2 我是 ...
- PADS 导Gerber文件
PCB也画了好几年,投板时都是直接发PCB文件,突然间客户让我导出Gerber文件, 一时半会还挺棘手的,上网不停的搜啊搜啊,虽然最终还是搞定了,但耽误了不少时间. 现总结下,把所有相关设置一步一步的 ...
- memcached添加IP白名单,只允许指定服务器调用
由于memcached默认安装是不用配置密码的(具体的密码配置我也没怎么研究,据说是有的,大家感兴趣去找一找) 然而memcached链接也是非常简单的 linux命令链接使用 Telnet IP地 ...