传送门

(分析见正睿2018.10.1笔记)

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
struct node {
int pre,sur,ans,sum;
};
node d[];
inline node work(node x,node y){
node res;
res.sum=x.sum+y.sum;
res.pre=max(x.pre,x.sum+y.pre);
res.sur=max(y.sur,y.sum+x.sur);
res.ans=max(max(x.ans,y.ans),x.sur+y.pre);
return res;
}
inline void update(int le,int ri,int wh,int pl,int k){
if(le==ri){
d[wh].pre=d[wh].sur=d[wh].ans=d[wh].sum=k; return;
}
int mid=(le+ri)>>;
if(mid>=pl)update(le,mid,wh<<,pl,k);
else update(mid+,ri,wh<<|,pl,k);
d[wh]=work(d[wh<<],d[wh<<|]);
return;
}
inline node q(int le,int ri,int wh,int x,int y){
if(le>=x&&ri<=y){
return d[wh];
}
int mid=(le+ri)>>,cnt=;
node a,b;
if(mid>=x)cnt+=,a=q(le,mid,wh<<,x,y);
if(mid<y)cnt+=,b=q(mid+,ri,wh<<|,x,y);
if(cnt==)return a;
if(cnt==)return b;
return work(a,b);
}
int main(){
int n,m,i,j,k,x,y;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&x);
update(,n,,i,x);
}
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d%d",&k,&x,&y);
if(k==){
update(,n,,x,y);
}else {
printf("%d\n",q(,n,,x,y).ans);
}
}
return ;
}

spoj1716 Can you answer these queries III的更多相关文章

  1. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  2. GSS3 SPOJ 1716. Can you answer these queries III gss1的变形

    gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...

  3. 数据结构(线段树):SPOJ GSS3 - Can you answer these queries III

    GSS3 - Can you answer these queries III You are given a sequence A of N (N <= 50000) integers bet ...

  4. 线段树 SP1716 GSS3 - Can you answer these queries III

    SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] ...

  5. 「 SPOJ GSS3 」 Can you answer these queries III

    # 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段 ...

  6. Can you answer these queries III

    Can you answer these queries III 题目:洛谷 SPOJ [题目描述] 给定长度为N的数列A,以及M条指令,每条指令可能是以下两种之一: 1.“0 x y”,把A[x]改 ...

  7. Can you answer these queries III(线段树)

    Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l ...

  8. [SPOJ1716] GSS3 - Can you answer these queries III

    线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include ...

  9. SPOJ GSS3 Can you answer these queries III

    Time Limit: 330MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are g ...

随机推荐

  1. LeetCode OJ:Symmetric Tree(对称的树)

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  2. 骨骼动画 cocos2d-x + cocoStudio <cocos2d-x : version 2.2.0>

    cocos2d-x version 2.2.0 首先,在 HelloWorldScene.cpp 中的 init()函数中 添加如下代码 (资源文件可以直接到 cocos2d-x 中获取) #incl ...

  3. Smarty的模板中不允许PHP的代码?

    /****************************************************************************** * Smarty的模板中不允许PHP的代 ...

  4. New Year and Counting Cards

    Your friend has n cards. You know that each card has a lowercase English letter on one side and a di ...

  5. 【数论】卡塔兰数 Catalan

    一.简介 设$h(0)=1$,$h(1)=1$,Catalan数满足递推式 $h(n) = h(0) \ast h(n-1) + h(1)\ast h(n-2) + \cdots + h(n-1)\a ...

  6. 高性能服务器架构 的几个注意点 (High-Performance Server Architecture)

    High-Performance Server Architecture 高性能服务器架构 来源:http://pl.atyp.us/content/tech/servers.html译文来源:htt ...

  7. 10.Selenium+Python+任务计划程序实现定时发送邮件

    一.python具体代码实现 # coding=utf-8 import smtplib from email.mime.text import MIMEText from email.header ...

  8. Linux基础命令-文本文件查看工具

    文本文件查看工具 cat concatenate 文本文件查看工具 cat /etc/fstab cat [OPTION]... [FILE]... -n:给显示的文本行编行 -E:显示行结束符 ta ...

  9. HDU5468(dfs序+容斥原理)

    Puzzled Elena Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  10. md5加密(1)

    package com.js.ai.modules.pointwall.util; import java.security.MessageDigest; import java.security.N ...