[BZOJ3784]树上的路径 点分治序+ST表

点分治序就是每次点分治时的dfs序拼起来。点分治序的长度应该是nlogn的。
然后对于每一条路径(u,v),在出现了u的分治结构中,v总是在点分治序的一段区间里,就可以同NOI2010超级钢琴一样维护了,就是从堆中取出最大值,并把所在区间再分成两部分扔进堆里,重复m次即可。复杂度O(nlog^2n)。
代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int maxn=50010;
const int mlgn=900010;
int n,m,tim,a[mlgn],fz[maxn],ed[maxn],sz[maxn],st[mlgn][20],lg[mlgn];
bool vis[maxn];
struct edge
{
    int t,w;
    edge *next;
}*con[maxn];
struct node
{
    int p,l,r,w,d;
}t[mlgn];
inline bool operator <(const node &p,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值