(简单) 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张海报,海报 ...
随机推荐
- 使用Spring 3的@value简化配置文件的读取 (转)
Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在applicationContext.xml文件中配置properties文件 & ...
- [maven] 新建项目一直提示loading archetype list
Maven's JRE is running out of memory. Under Build > Build Tools > Maven > Importing, set &q ...
- webview h5页面 关闭
说明:在 ios 安卓 客户端上的h5页面执行完毕关闭h5页面 引入的js在文件中的xhdoctor_mobile.rar
- select初始化默认选项
在写select时由于 在数据库中的得到的值都是字典型的值0,1,2所以在初始化的时候要
- java 实例变量和类变量的区别
Example4_10.java public class Example4_10 { public static void main(String args[]) { Lader.下底=100; / ...
- PAT1003
As an emergency rescue team leader of a city, you are given a special map of your country. 作为一个城市的紧急 ...
- 转:Emmet 学习之路 - 2 基本语法
http://blog.csdn.net/jizhongchun/article/details/8472755 导读:Emmet的基本语法.学习步骤是:1 基本语法: 2 html命令: 3 css ...
- hdu_1007_Quoit Design(最近点对)
题目连接:hdu_1007_Quoit Design 题意: 给你平面上的一些点,让你找出这些点的最近点对的距离 题解: 采用分治,达到O(nlognlogn)的时间复杂度就能艹过去了 #includ ...
- 【转】The magic behind array length property
Developer deals with arrays every day. Being a collection, an important property to query is the num ...
- MyEclipse8.5 无法安装ADT解决办法
打开MYECLIPSE.点击菜单栏的help ->my eclipse configure center .然后add site 指向 https://dl-ssl.google.com/an ...