LCT板子,打个lazy即可

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <algorithm>
# include <string.h>
# include <map>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll; IL ll Read(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
return x * z;
} const int MAXN(200010);
int n, S[MAXN], ch[2][MAXN], fa[MAXN], mx[MAXN], mi[MAXN], sum[MAXN], rev[MAXN], w[MAXN], tag[MAXN]; IL bool Son(RG int x){ return ch[1][fa[x]] == x; } IL bool Isroot(RG int x){ return ch[0][fa[x]] != x && ch[1][fa[x]] != x; } IL void Update(RG int x){
sum[x] = sum[ch[0][x]] + sum[ch[1][x]] + w[x];
mx[x] = max(mx[ch[0][x]], mx[ch[1][x]]);
mi[x] = min(mi[ch[0][x]], mi[ch[1][x]]);
if(x > n) mx[x] = max(mx[x], w[x]), mi[x] = min(mi[x], w[x]);
} IL void Down(RG int x){ swap(mi[x], mx[x]); sum[x] = -sum[x]; mi[x] = -mi[x]; mx[x] = -mx[x]; w[x] = -w[x]; tag[x] ^= 1; } IL void Pushdown(RG int x){
if(tag[x]){
tag[x] = 0;
if(ch[0][x]) Down(ch[0][x]);
if(ch[1][x]) Down(ch[1][x]);
}
if(rev[x]) rev[x] = 0, rev[ch[0][x]] ^= 1, rev[ch[1][x]] ^= 1, swap(ch[0][x], ch[1][x]);
} IL void Rot(RG int x){
RG int y = fa[x], z = fa[y], c = Son(x);
if(!Isroot(y)) ch[Son(y)][z] = x; fa[x] = z;
ch[c][y] = ch[!c][x]; fa[ch[c][y]] = y;
ch[!c][x] = y; fa[y] = x; Update(y);
} IL void Splay(RG int x){
RG int top = 0; S[++top] = x;
for(RG int y = x; !Isroot(y); y = fa[y]) S[++top] = fa[y];
while(top) Pushdown(S[top--]);
for(RG int y = fa[x]; !Isroot(x); Rot(x), y = fa[x])
if(!Isroot(y)) Son(x) ^ Son(y) ? Rot(x) : Rot(y);
Update(x);
} IL void Access(RG int x){ for(RG int y = 0; x; y = x, x = fa[x]) Splay(x), ch[1][x] = y, Update(x); } IL void Makeroot(RG int x){ Access(x); Splay(x); rev[x] ^= 1; } IL int Findroot(RG int x){ Access(x); Splay(x); while(ch[0][x]) x = ch[0][x]; return x; } IL void Split(RG int x, RG int y){ Makeroot(x); Access(y); Splay(y); } IL void Link(RG int x, RG int y){ Makeroot(x); fa[x] = y; } IL void Cut(RG int x, RG int y){ Split(x, y); fa[x] = ch[0][y] = 0; } int main(RG int argc, RG char* argv[]){
n = Read();
for(RG int i = 0; i <= n; i++) mx[i] = -2e9, mi[i] = 2e9;
for(RG int i = 1; i < n; i++){
RG int u = Read() + 1, v = Read() + 1;
Link(u, n + i); Link(n + i, v);
sum[n + i] = mx[n + i] = mi[n + i] = w[n + i] = Read();
}
RG int Q = Read(), u, v; RG char c[10];
while(Q--){
scanf(" %s", c); u = Read(); v = Read();
if(c[0] == 'C') Splay(n + u), w[n + u] = v, Update(n + u);
else{
u++; v++; Split(u, v);
if(c[0] == 'N') Down(v);
else if(c[0] == 'S') printf("%d\n", sum[v]);
else if(c[1] == 'A') printf("%d\n", mx[v]);
else printf("%d\n", mi[v]);
}
}
return 0;
}

bzoj2157的更多相关文章

  1. 【BZOJ2157】旅游(树链剖分,Link-Cut Tree)

    [BZOJ2157]旅游(树链剖分,Link-Cut Tree) 题面 Description Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥 ...

  2. 【BZOJ2157】旅游 树链剖分+线段树

    [BZOJ2157]旅游 Description Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本 ...

  3. [BZOJ2157]旅游(树链剖分/LCT)

    树剖裸题,当然LCT也可以. 树剖: #include<cstdio> #include<algorithm> #define ls (x<<1) #define ...

  4. bzoj2157旅游

    bzoj2157旅游 题意: 给定有权树,支持单边权修改,路径边权取相反数,路径边权求和,路径边权求最大最小值. 题解: 用link-cut tree link-cut tree与树链剖分有些类似,都 ...

  5. 【BZOJ2157】旅游 LCT

    模板T,SB的DMoon..其实样例也是中国好样例...一开始不会复制,yangyang:找到“sample input”按住shift,按page down.... #include <ios ...

  6. BZOJ2157: 旅游

    传送门 先讲一个悲伤地故事 RunID User Problem Result Memory Time Language Code_Length Submit_Time 1635823 Cydiate ...

  7. BZOJ2157 旅行 模拟

    题目内容: Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T 城的任意两个景点之间有且只有一条 ...

  8. [bzoj2157]旅游 (lct)

    这个应该也算裸的模板题吧..主要是边权的问题,对于每条边u->v,我们可以新建一个节点代替他,把边的信息弄到新的点上,就变成u->x->v了... 当然了这样的话要防止u和v这些没用 ...

  9. ⌈洛谷1505⌋⌈BZOJ2157⌋⌈国家集训队⌋旅游【树链剖分】

    题目链接 [洛谷] [BZOJ] 题目描述 Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T ...

随机推荐

  1. CocosCreator游戏开发---菜鸟学习之路(一)

    PS(废话): 辞职后在家好久好久了,久到经济不允许了,接着就准备再次出去找工作了,然而工作哪有那么好找,特别是像我这种菜鸟.而且我还准备转行,准备去做游戏,技能等级接近于0,那工作就更难找了.既然如 ...

  2. 05-Git

    [Git]   [安装git] $ yum install git  #安装git $ ssh-keygen  #遇到输入符直接回车 $ cat ~/.ssh/id_rsa.pub #将这里的信息添加 ...

  3. 前端小白的gulp入门

    gulp新手入门 全局安装 cnpm install -g gulp 本地安装cnpm install gulp -D 如果项目没有package.json,记得npm init 安装插件cnpm i ...

  4. mysql之mysql_config_editor

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn mysql_config_editor允许你把登录的身份验证信息存储 ...

  5. 35 个 jQuery 小技巧

    1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return ...

  6. Git版本控制的基本命令

    安装完了GIT首先要自报家门,否则代码不能提交 git config --global user.name "Your Name" git config --global user ...

  7. POJ - 1733 Parity game 种类并查集+离散化

    思路:d(i, j)表示区间(i, j]的1的个数的奇偶性.输入最多共有5000*2个点,需要离散化处理一下.剩下的就是并查集判冲突. AC代码 #include <cstdio> #in ...

  8. @EnableAsync @Asnc 以及4种拒绝策略

    根据不同的场景,可以选择不同的拒绝策略,如果任务非常重要,线程池队列满了,可以交由调用者线程同步处理. 如果是一些不太重要日志,可以直接丢弃掉. 如果一些可以丢弃,但是又需要知道被丢弃了,可以使用Th ...

  9. 压缩tar命令

    option z表示压缩,所以才有后面的.gz, c表示创建这个压缩包,v是可视,能看到其打包和压缩的过程,f表示文件 zcvf 命令格式为 先压缩后跟压缩的目录 tar zcvf /home/xia ...

  10. Supervisor使用说明

    Supervisor是一个 Python 开发的 client/server 系统,可以管理和监控类 UNIX 操作系统上面的进程.它可以同时启动,关闭多个进程,使用起来特别的方便. 1.组成部分 s ...