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. [Python Study Notes]with的使用

    在 Python 2.5 中, with 关键字被加入.它将常用的 try ... except ... finally ... 模式很方便的被复用.看一个最经典的例子: with open('fil ...

  2. [Python Study Notes]批量将ppt转换为pdf v1.0

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  3. HP中spl_autoload_register函数的用法

    spl_autoload_register(PHP 5 >= 5.1.2) spl_autoload_register - 注册__autoload()函数 说明bool spl_autoloa ...

  4. Halcon一日一练:图像拼接技术

    图像拼接技术就是针对同一场景的一系列图片,根据图片的特征,比如位置,重叠部分等,拼接成一张大幅的宽视角的图像. 图像拼接要求拼接后图像最大程度的与原图一致,失真尽可能的小,并且要尽量做到天衣无缝即没有 ...

  5. OpenCMS模板的导出和OpenCMS网站的导出

    1.OpenCMS模板的导出 (1)切换到Administration视图,单击Module Management,如图所示:   (2)导出位置:tomcat根目录\webapps\opencms\ ...

  6. Thymeleaf入门基础

    一.简介 1.thymeleaf优点 ①是一个支持html原型的自然引擎,它在html标签增加额外的属性来达到模板+数据的展示方式,由于浏览器解释html时,忽略未定义的标签属性,因此thymelea ...

  7. springmvc+mybatis+mysql 数据库插入中文是乱码

    java web项目,前台页面的表单数据,插入到数据库时,结果出现乱码"???"的问题,断断续续折腾了一天时间,废话不说,步骤如下: 一:在web.xml中配置:编码格式拦截器 & ...

  8. bzoj1555 KD之死 贪心+堆优化

    1555: KD之死 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 124  Solved: 54[Submit][Status][Discuss] D ...

  9. Shell脚本查看linux系统性能瓶颈(转)

    Shell脚本查看linux系统性能瓶颈(转自:http://blog.51cto.com/lizhenliang/1687612) [root@test ~]# cat show_sys_info. ...

  10. HDU1560 DNA sequence IDA* + 强力剪枝 [kuangbin带你飞]专题二

    题意:给定一些DNA序列,求一个最短序列能够包含所有序列. 思路:记录第i个序列已经被匹配的长度p[i],以及第i序列的原始长度len[i].则有两个剪枝: 剪枝1:直接取最长待匹配长度.1900ms ...