Spoj 6779 Can you answer these queries VII 树链剖分 在树上任意路径的最大子段和 区间修改点权

这篇博客详细介绍了如何使用树链剖分解决Spoj 6779问题,即在树上找到任意路径的最大子段和,并支持区间修改点权。在询问过程中,从浅到深遍历节点,记录左最大连续子段和。当遇到同一重链上的节点时,需要考虑四种特殊情况来合并子段和。线段树的实现与同类问题相似。
摘要由CSDN通过智能技术生成

题目链接:点击打开链接

题意:

rt。。

在询问时,两端向上爬时记录从深度浅的到深度深的方向上的 (也就是左最大连续子段和)

最后两个点在同一条重链上时合并。

合并时要注意有4种情况, 详见代码。

线段树部分和5相似。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
inline void rd(int &n){    
	n = 0;
    bool tmp = 0;    
    char c = getchar();    
    while((c < '0' || c > '9') && c != '-' ) c = getchar();   
    if(c == '-') c = getchar(), tmp = 1;    
    while(c >= '0' && c <= '9') n *= 10, n += (c - '0'),c = getchar();    
	if(tmp) n = -n;
}    
#define N 100100
#define hehe 10001
#define L(x) tree[x].l
#define R(x) tree[x].r
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
#define Sum(x) tree[x].sum
#define Max(x) tree[x].max
#define Lmax(x) tree[x].lmax
#define Rmax(x) tree[x].rmax
#define Lazy(x) tree[x].lazy
#define Siz(x) tree[x].siz()
struct node{
    int l, r;
    int mid(){return (l+r)>>1;}
	int siz(){return r-l+1;}
    int lmax, rmax, max, sum, lazy;
}tree[N<<2];
int n, a[N], Q, fw[N];
void updata_point(int val, int id){Lmax(id) = Rmax(id) = Max(id) = Sum(id) = val * Siz(id);}
void push_down(int id){
	if(L(id) == R(id))retur
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值