简单题,主要为了练手。

 #include <cstdio>
#include <iostream>
#define maxn 100010
using namespace std; namespace L {
int pnt[maxn], pre[maxn], son[maxn][], rtg[maxn], val[maxn], mxv[maxn]; inline void update( int nd ) {
mxv[nd] = max( val[nd], max(mxv[son[nd][]],mxv[son[nd][]]) );
}
void rotate( int nd, int d ) {
int p = pre[nd];
int s = son[nd][!d];
int ss = son[s][d];
son[nd][!d] = ss;
son[s][d] = nd;
if( p ) son[p][ nd==son[p][] ] = s;
else pnt[s] = pnt[nd];
pre[nd] = s;
pre[ss] = nd;
pre[s] = p;
update(nd);
update(s);
}
void pushdown( int nd ) {
if( rtg[nd] ) {
int &ls=son[nd][], &rs=son[nd][];
swap(ls,rs);
rtg[ls] ^= ;
rtg[rs] ^= ;
rtg[nd] = ;
}
}
void bigpush( int nd ) {
if( pre[nd] ) bigpush(pre[nd]);
pushdown(nd);
}
void splay( int nd, int top= ) {
bigpush(nd);
while( pre[nd]!=top ) {
int p = pre[nd];
int nl = nd==son[p][];
if( pre[p]==top ) {
rotate( p, nl );
} else {
int pp = pre[p];
int pl = p==son[pp][];
if( nl==pl ) {
rotate( pp, pl );
rotate( p, nl );
} else {
rotate( p, nl );
rotate( pp, pl );
}
}
}
}
void access( int nd ) {
int u = nd;
int v = ;
while( u ) {
splay(u);
int s = son[u][];
pre[s] = ;
pnt[s] = u;
pre[v] = u;
son[u][] = v;
update(u);
v = u;
u = pnt[u];
}
splay(nd);
}
void init( int n ) {
for( int i=; i<=n; i++ )
pnt[i] = pre[i] = son[i][] = son[i][]
= rtg[i] = val[i] = mxv[i] = ;
}
void makeroot( int nd ) {
access(nd);
rtg[nd] ^= ;
}
void link( int u, int v ) {
makeroot(u);
makeroot(v);
pnt[u] = v;
}
void inc_val( int nd, int w ) {
splay( nd );
val[nd] += w;
update( nd );
}
int qu_max( int u, int v ) {
makeroot(u);
access(v);
return max( val[v], mxv[son[v][]] );
}
}; int n, q; int main() {
scanf( "%d", &n );
L::init(n);
for( int i=,u,v; i<=n; i++ ) {
scanf( "%d%d", &u, &v );
L::link(u,v);
}
scanf( "%d", &q );
while( q-- ) {
char ch[];
int u, v, w;
scanf( "%s", ch );
if( ch[]=='I' ) {
scanf( "%d%d", &u, &w );
L::inc_val(u,w);
} else {
scanf( "%d%d", &u, &v );
printf( "%d\n", L::qu_max(u,v) );
}
}
}

Uva1553 Caves and Tunnels LCT的更多相关文章

  1. URAL 题目1553. Caves and Tunnels(Link Cut Tree 改动点权,求两点之间最大)

    1553. Caves and Tunnels Time limit: 3.0 second Memory limit: 64 MB After landing on Mars surface, sc ...

  2. ural1553 Caves and Tunnels

    Caves and Tunnels Time limit: 3.0 secondMemory limit: 64 MB After landing on Mars surface, scientist ...

  3. URAL1553 Caves and Tunnels 树链剖分 动态树

    URAL1553 维护一棵树,随时修改某个节点的权值,询问(x,y)路径上权值最大的点. 树是静态的,不过套动态树也能过,时限卡的严就得上树链剖分了. 还是那句话 splay的核心是splay(x) ...

  4. URAL 1553. Caves and Tunnels 树链拆分

    一颗树 每次出发点右键值是0 2操作模式1.第一i右键点值添加x 2.乞讨u至v在这条路上右上方值 树为主的连锁分裂称号 #include <cstdio> #include <cs ...

  5. LCT(link cut tree) 动态树

    模板参考:https://blog.csdn.net/saramanda/article/details/55253627 综合各位大大博客后整理的模板: #include<iostream&g ...

  6. 一堆LCT板子

    搞了一上午LCT,真是累死了-- 以前总觉得LCT高大上不好学不好打,今天打了几遍感觉还可以嘛= =反正现在的水平应付不太难的LCT题也够用了,就这样好了,接下来专心搞网络流. 话说以前一直YY不出来 ...

  7. 动态树之LCT(link-cut tree)讲解

    动态树是一类要求维护森林的连通性的题的总称,这类问题要求维护某个点到根的某些数据,支持树的切分,合并,以及对子树的某些操作.其中解决这一问题的某些简化版(不包括对子树的操作)的基础数据结构就是LCT( ...

  8. 在此为LCT开一个永久的坑

    其实我连splay都还不怎么会. 今天先抄了黄学长的bzoj2049,以后一定要把它理解了. 写LCT怎么能不%数据结构大神yeweining呢?%%%chrysanthemums  %%%切掉大森林 ...

  9. 【BZOJ2157】旅游 LCT

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

随机推荐

  1. 【IDEA】IDEA中maven项目pom.xml依赖不生效解决

    问题: 今天在web项目中需要引入poi相关jar包.查看之下才发现pom.xml中的依赖虽然已经下载到了本地仓库 repository,但是却没有加入到项目路径的 Extenal Libraries ...

  2. 图片异或(xor)getflag

    题目地址:https://files.cnblogs.com/files/nul1/flag_enc.png.tar 这题是源于:网鼎杯minified 经过测试隧道红色最低通道异常.其余均正常.所以 ...

  3. [转载]锁无关的数据结构与Hazard指针——操纵有限的资源

    Lock-Free Data Structures with Hazard Pointers 锁无关的数据结构与Hazard指针----操纵有限的资源 By Andrei Alexandrescu a ...

  4. fullpage.js 具体使用方法

    1.fullpage.js  下载地址 https://github.com/alvarotrigo/fullPage.js 2.fullPage.js 是一个基于 jQuery 的插件,它能够很方便 ...

  5. untiy3d学习笔记

    Unity3d 记录 1.63讲 主要讲了menicam 从3D软件里面导出过后,注意如果是人物模型命名一定要非常清晰并且对称.选择到模型后等到到humanoid后可以使用menicam.然后使用me ...

  6. Django之管理权限

    什么是权限: 谁对什么资源能做什么操作. 管理权限的实现有很多,这里实现一个最简单的管理权限的实现方式:rbac   ( role based access control ) 实现的一个基本思路: ...

  7. FPGA 17最佳论文导读 ESE: Efficient Speech Recognition Engine with Compressed LSTM on FPGA

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.机器学习技术感兴趣的同学加入. 后面陆续写一些关于神经网络加 ...

  8. 【hdoj_1865】1sting(递推+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...

  9. scrapy 学习笔记2

    本章学习爬虫的 回调和跟踪链接 使用参数 回调和跟踪链接 上一篇的另一个爬虫,这次是为了抓取作者信息 # -*- coding: utf-8 -*- import scrapy class Myspi ...

  10. SQL Server Connection Pooling (ADO.NET)

    SQL Server Connection Pooling (ADO.NET) Connecting to a database server typically consists of severa ...