SP1716 GSS3】的更多相关文章

SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] 的最大子段和 依旧是维护最大子段和,还是再敲一遍比较好. code: #include<iostream> #include<cstdio> #define ls(o) o<<1 #define rs(o) o<<1|1 using namespace std…
题意翻译 nnn 个数, qqq 次操作 操作0 x y把 AxA_xAx​ 修改为 yyy 操作1 l r询问区间 [l,r][l, r][l,r] 的最大子段和 题目描述 You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th ele…
问题描述 [LG-SP1716](https://www.luogu.org/problem/SP1716] 题解 GSS 系列的第三题,在第一题的基础上带单点修改. 第一题题解传送门 在第一题的基础上,增加一个单点修改就完事了. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; template <typename Tp> void read(Tp &x){ x=0;char ch=1;int f…
GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) 的最大子段和,那么 \[f[i] = max(f[i - 1] + a[i], a[i])\] \[g[i] = max(g[i - 1], f[i])\] 发现只跟前一项有关.我们希望使用矩阵乘法的思路,但是矩阵乘法通常只能适用于递推问题.因此我们引入广义矩阵乘法. 矩阵乘法问题可分治的原因在于…
题面 题解 相信大家写过的传统做法像这样:(这段代码蒯自Karry5307的题解) struct SegmentTree{ ll l,r,prefix,suffix,sum,maxn; }; //... inline void update(ll node) { ll res; tree[node].sum=tree[node<<1].sum+tree[(node<<1)|1].sum; tree[node].maxn=max(tree[node<<1].maxn,tr…
题意翻译 \(n\) 个数,\(q\) 次操作 操作\(0\) \(x\) \(y\)把\(A_x\) 修改为\(y\) 操作\(1\) \(l\) \(r\)询问区间\([l, r]\)的最大子段和 输入输出格式 输入格式: The first line of input contains an integer N. The following line contains N integers, representing the sequence A1..AN. The third line…
Code: #include <bits/stdc++.h> #define N 50001 #define ll long long #define lson now<<1 #define rson now<<1|1 #define inf 1000000000 #define setIO(s) freopen(s".in","r",stdin) using namespace std; ll A[N]; struct Matr…
小结:昨天因为整理课件,调代码耗费了大量时间,所以没来得及整理作业,这两天主要做的题目是关于树链剖分和线段树的,难度大约都是省选难度,毕竟只要涉及到树链剖分难度就肯定不低. 一. 完成的题目: 洛谷P3870,洛谷P2628,洛谷P3384,洛谷P2590,洛谷P3178,洛谷P2014,洛谷P4092,SP1716 二. 1. 完成题目数:8道. 2. 未完成6个题目的原因: 3. 复习的知识点:树链剖分,树型dp,dfs序,线段树 4.不会题目:SP6779,洛谷P1823 三: 1.洛谷…
目录 前言 开始 更进一步 前言 最后一届NOIPTG的day2T3对于动态DP的普及起到了巨大的作用.然而我到现在还不会 开始 SP1716 GSS3 - Can you answer these queries III 题解位置 这道题的题目大意就是维护动态序列最大子段和.一个比较显然的想法就是用线段树维护\(lmax,rmax,sum,max\)即可.但是我们不想放弃DP的优良性质,于是就有了优良的动态DP. 对于这道题目,如果不考虑修改操作,那么DP就是这样的: 令\(F[i]\)表示以…
题目链接 之前用线段树写了一遍,现在用\(ddp\)再写一遍. #include <cstdio> #define lc (now << 1) #define rc (now << 1 | 1) inline int max(int a, int b){ return a > b ? a : b; } const int INF = 2147483647 >> 2; const int MAXN = 50010; inline int read(){…