Description

The little cat takes over the management of a new park. There is a large circular statue in the center of the park, surrounded by N pots of flowers. Each potted flower will be assigned to an integer number (possibly negative) denoting how attractive it is. See the following graph as an example:

(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,环+线段树。的更多相关文章

  1. POJ 2750 Potted Flower(线段树的区间合并)

    点我看题目链接 题意 : 很多花盆组成的圆圈,每个花盆都有一个值,给你两个数a,b代表a位置原来的数换成b,然后让你从圈里找出连续的各花盆之和,要求最大的. 思路 :这个题比较那啥,差不多可以用DP的 ...

  2. 【POJ 2750】 Potted Flower(线段树套dp)

    [POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4566   ...

  3. POJ 2750 Potted Flower (线段树区间合并)

    开始懵逼找不到解法,看了网上大牛们的题解才发现是区间合并...  给你n个数形成一个数列环,然后每次进行一个点的修改,并输出这个数列的最大区间和(注意是环,并且区间最大只有n-1个数) 其实只需要维护 ...

  4. POJ.2750.Potted Flower(线段树 最大环状子段和)

    题目链接 /* 13904K 532ms 最大 环状 子段和有两种情况,比如对于a1,a2,a3,a4,a5 一是两个端点都取,如a4,a5,a1,a2,那就是所有数的和减去不选的,即可以计算总和减最 ...

  5. POJ 2750 Potted Flower(线段树+dp)

    题目链接 虽然是看的别的人思路,但是做出来还是挺高兴的. 首先求环上最大字段和,而且不能是含有全部元素.本来我的想法是n个元素变为2*n个元素那样做的,这样并不好弄.实际可以求出最小值,总和-最小,就 ...

  6. POJ 2750 Potted Flower

    Potted Flower Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3872   Accepted: 1446 Des ...

  7. POJ 2750 Potted Flower (单点改动求线段树上最大子序列和)

    题目大意: 在一个序列上每次改动一个值,然后求出它的最大的子序列和. 思路分析: 首先我们不考虑不成环的问题.那就是直接求每一个区间的最大值就好了. 可是此处成环,那么看一下以下例子. 5 1 -2 ...

  8. POJ 2828 Buy Tickets(线段树 树状数组/单点更新)

    题目链接: 传送门 Buy Tickets Time Limit: 4000MS     Memory Limit: 65536K Description Railway tickets were d ...

  9. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

随机推荐

  1. 上海赛趣-top.mainFrame.tabAddHandler方法详解

    top.mainFrame.tabAddHandler("item"+Id,'项目:'+itemname,'<%=basePath%>bizitem/goEditIte ...

  2. css 重新学习系列(1)

    来源: http://www.cnblogs.com/Zigzag/archive/2009/04/16/1394356.html CSS之Position详解(1) CSS的很多其他属性大多容易理解 ...

  3. POJ 2182/暴力/BIT/线段树

    POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...

  4. CI 路由设置

    $route['news/show/(:num)']='news/show/$1';   前边是匹配 网址   后边是  指定控制器 在application/config/文件夹下有routes.p ...

  5. PHP的PDO操作实例

    try{             $dbms='mysql';          //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数       $host='127 ...

  6. java 对象的上转型对象(父类)

    Example5_10.java class 类人猿 { void crySpeak(String s) { System.out.println(s); } } class People exten ...

  7. js遍历table 和 jquery 遍历table

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  8. 4D(DRG、DLG、DOM、DEM)数据 概念

    抱歉原文链接未知 Technorati 标签: DRG,DLG,DOM,DEM 以下有不同的说法,但是意思都很相近. 一. DOM (数字正射影像图):利用数字高程模型对扫描处理的数字化的航空相片.遥 ...

  9. ping命令使用技巧(一次Ping多个地址)

    打开windows 命令行 窗口, 在命令行输入以下命令: for /l %i in (1,1,255) do ping -n 1  -w 60 192.168.0.%i  | find " ...

  10. PAT1006

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...