题意

Sol

会了GSS1,GSS3就比较无脑了

直接加个单点修改即可,然后update一下

/*

*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define rg register
#define sc(x) scanf("%d", &x);
#define pt(x) printf("%d ", x);
#define db(x) double x
#define rep(x) for(int i = 1; i <= x; i++)
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[( << )], *p1 = buf, *p2 = buf;
char obuf[<<], *O = obuf;
#define OS *O++ = '\n';
using namespace std;
using namespace __gnu_pbds;
const int MAXN = , INF = 1e9 + , mod = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
void print(int x) {
if(x > ) print(x / );
*O++ = x % + '';
}
#define ls k << 1
#define rs k << 1 | 1
int N, M;
int a[MAXN];
struct Node {
int l, r, lmx, rmx, mx, sum;
}T[MAXN << ];
void update(int k) {
T[k].sum = T[ls].sum + T[rs].sum;
T[k].mx = max(T[ls].mx, T[rs].mx);
T[k].mx = max(T[k].mx, T[ls].rmx + T[rs].lmx);
T[k].rmx = max(T[rs].rmx, T[rs].sum + T[ls].rmx);
T[k].lmx = max(T[ls].lmx, T[ls].sum + T[rs].lmx);
}
void Build(int k, int ll, int rr) {
T[k] = (Node) {ll, rr, , , };
if(ll == rr) {
T[k].lmx = T[k].rmx = T[k].mx = T[k].sum = a[ll];
return ;
}
int mid = ll + rr >> ;
Build(ls, ll, mid);
Build(rs, mid + , rr);
update(k);
}
Node merge(Node a, Node b) {
Node now;
now.sum = a.sum + b.sum;
now.mx = max(a.mx, b.mx);
now.mx = max(now.mx, a.rmx + b.lmx);
now.rmx = max(b.rmx, b.sum + a.rmx);
now.lmx = max(a.lmx, a.sum + b.lmx);
// printf("%d %d %d %d\n", now.mx, now.lmx, now.rmx, now.sum);
return now;
}
Node Query(int k, int ll, int rr) {
Node ans = (Node) {, , , , };
if(ll <= T[k].l && T[k].r <= rr) return T[k];
int mid = T[k].l + T[k].r >> ;
/*if(ll <= mid) ans = Query(ls, ll, rr);
if(rr > mid) ans = merge(ans, Query(rs, ll, rr));*/
if(ll > mid) return Query(rs, ll, rr);
else if(rr <= mid) return Query(ls, ll, rr);
else return merge(Query(ls, ll, rr), Query(rs, ll, rr));
return ans;
}
void PointChange(int k, int pos, int val) {
if(T[k].l == T[k].r) {
T[k].lmx = T[k].rmx = T[k].mx = T[k].sum = val;
return ;
}
int mid = T[k].l + T[k].r >> ;
if(pos <= mid) PointChange(ls, pos, val);
if(pos > mid) PointChange(rs, pos, val);
update(k);
}
main() {
//freopen("a.in", "r", stdin);
N = read();
for(int i = ; i <= N; i++) a[i] = read();
Build(, , N);
int M = read();
while(M--) {
int opt = read(), x = read(), y = read();
if(opt == ) printf("%d\n", Query(, x, y).mx);
else PointChange(, x, y);
}
//fwrite(obuf, O-obuf, 1 , stdout);
return ;
}
/*
5
-10 12 1 -45 134
5
1 5
2 3
4 5
1 4
3 5
*/

SPOJ1716 GSS3(线段树)的更多相关文章

  1. SPOJ GSS3 线段树系列1

    SPOJ GSS系列真是有毒啊! 立志刷完,把线段树搞完! 来自lydrainbowcat线段树上的一道例题.(所以解法参考了lyd老师) 题意翻译 n 个数, q 次操作 操作0 x y把 Ax 修 ...

  2. SP1716 GSS3(线段树+矩阵乘法)

    Code: #include <bits/stdc++.h> #define N 50001 #define ll long long #define lson now<<1 ...

  3. SP1716 GSS3 - Can you answer these queries III - 动态dp,线段树

    GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) ...

  4. SPOJ GSS3 Can you answer these queries III ——线段树

    [题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #inc ...

  5. SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并

    Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...

  6. Wannafly挑战赛10 D 小H的询问(线段树)

    题目链接  Problem D 这个题类似 SPOJ GSS3 做过那个题之后其实就可以秒掉这题了. 考虑当前线段树维护的结点 在那道题的基础上,这个题要多维护几个东西,大概就是左端点的奇偶性,右端点 ...

  7. bzoj3932--可持久化线段树

    题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...

  8. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  9. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

随机推荐

  1. bzoj 3160 万径人踪灭 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3160 求出关于一个位置有多少对对称字母,如果 i 位置有 f[i] 对,对答案的贡献是 2^ ...

  2. js中实现子页面向父页面中赋值

    (方法一) 父页面: <input id="input1" type="text"/> <a href="javascript:wi ...

  3. A-Z,a-z,0-9的unicode编码表

    1.转自:https://blog.csdn.net/fedawn/article/details/7307993 A-Z 的 Unicode 字符编码表     十进制  十六进制 1.“A”的 U ...

  4. A - Combination Lock

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Scroog ...

  5. 20个Flutter实例视频教程-第08节: 保持页面状态

    博客地址: https://jspang.com/post/flutterDemo.html#toc-bb9 视频地址: https://www.bilibili.com/video/av397092 ...

  6. HDU - 4006 The kth great number multiset应用(找第k大值)

    The kth great number Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming ...

  7. input输入框修改后自动跳到最后一个字符

    <input class="m-form-control" onpaste="return false" placeholder="直播间名称& ...

  8. web前端_Vue框架_设置浏览器上方的标题和图标

    在创建Vue项目时一般会用默认的项目标题和图标,如下图所示: 不是很美观也可能不符合项目的需求,所以有时候就需要改变项目在浏览器上方的标签名称或者图标. 找到项目根目录的index.html,如图: ...

  9. git如何撤销上次提交

    git push提交完数据后后悔了怎么办? 写在前面的话重要:删除上次提交后本地和远程仓库的数据都将删除,所以删除上次提交前,记得备份备份备份数据!!! 1.直接删除上次提交,使用reset命令 gi ...

  10. 336. Palindrome Pairs(can't understand)

    Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that t ...