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. Linux下LNMP启动不了的问题总结(2015.05)

    [1] *****@*****-VirtualBox:~$ sudo /etc/init.d/mysql.server start Starting MySQL * Couldn't find MyS ...

  2. .Net Core和jexus配置HTTPS服务

    花了几天时间,看了好多篇博客,终于搞定了网站的HTTPS服务,借此写篇博客,来让有需要的朋友少走弯路. 一.环境介绍 1.Linux下在Docker容器中部署好了一个网站,该网站需要通过外部提供程序访 ...

  3. intellij idea maven springmvc 环境搭建

    1.   新建maven 工程 intellij idea 默认已经集成了maven, 直接点击下一步 2.   配置文件修改 pom.xml 文件 <?xml version="1. ...

  4. Linux-PATH_环境变量

    PATH变量         是linux系统里的一个环境变量,系统已经定义好了,我们不需要再定义. 作用:         是linux里使用的命令都存在在PATH变量后面指定的目录下,我们使用命令 ...

  5. pinvoke 数据交互笔记

    intptr to array string string[]  _outputStrArray=null;  int channelCount = 0;///返回数组大小            In ...

  6. 测试任务汇总v1.0

    2017.08.04 整理了目前我们所在团队需要做的日常任务 定义为v1.0

  7. Nginx的gzip压缩的原理和设置参数

    开启Nginx gzip压缩非常简单,达到的效果可以压缩静态文件大小.提高页面访问速度.节省流量和带宽是很有帮助的,也为用户省去了很多流量:唯一的不足就是开启之后服务器这边会增加运算,进行压缩运算处理 ...

  8. Entity Framework——配置文件设置

    可以使用配置文件或代码(EF6起)配置EF框架. 一.使用配置文件 安装Entity Framework自动生成的配置 当使用VS的NuGet自动安装Entity Framework(本文使用6.2. ...

  9. 【java学习笔记】线程

    1.线程的定义 ①继承Thread类,将执行的任务逻辑放到run方法中,调用start方法来开启线程 public class ThreadDemo { public static void main ...

  10. linux dns搭建

    DNS:域名解析(Domain Nmae System)正向解析:根据主机名称(域名)查找其对应的ip地址,这是最基本,最常用的功能反向解析:根据ip地址查找其对应的主机名称(域名),反垃圾邮件/安全 ...