省选模版复习——LCT

本文主要复习Link Cut Tree(LCT)的基础知识,并通过解决bzoj2157题目来实战应用LCT,探讨其在解决树形结构动态维护问题中的应用。
摘要由CSDN通过智能技术生成

bzoj2157 LCT裸题

#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
const int INF=1e9;
const int Maxn=40005;
int son[Maxn][2],sum[Maxn],minx[Maxn],maxx[Maxn];
int inv[Maxn],rev[Maxn],w[Maxn],fa[Maxn];
int n,m,x,y,i,a,u,v;
 
#define isroot(x) ( !((son[fa[x]][0]==x)||(son[fa[x]][1]==x)) )
void push1(int x){
  swap(son[x][0],son[x][1]);
  if (son[x][0]) rev[son[x][0]] ^= 1;
  if (son[x][1]) rev[son[x][1]] ^= 1;
  rev[x] = 0;
}
 
void push2(int x){
  int L = son[x][0], R = son[x][1];
  if (L){
    sum[L] = -sum[L];
    swap(minx[L],maxx[L]);
    minx[L] = -minx[L];
    maxx[L] = -maxx[L];
    inv[L] ^= 1;
    if (L>n) w[L]=-w[L];
  }
  if (R){
    sum[R] = -sum[R];
    swap(minx[R],maxx[R]);
    minx[R] = -minx[R];
    maxx[R] = -maxx[R];
    inv[R] ^= 1;
    if (R>n) w[R]=-w[R];
  }
  inv[x] = 0;
}
 
vo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值