没啥难的,inf 的值设小了调了半天~

code:

#include <bits/stdc++.h>
#define N 50003
#define lson t[x].ch[0]
#define rson t[x].ch[1]
using namespace std;
namespace IO
{
void setIO(string s)
{
string in=s+".in";
string out=s+".out";
freopen(in.c_str(),"r",stdin);
// freopen(out.c_str(),"w",stdout);
}
};
const int inf=0x3f3f3f3f;
int edges;
int sta[N],hd[N],to[N<<1],nex[N<<1];
struct node
{
int ch[2],minv,maxv,lmax,rmax,rev,tag,val,f;
}t[N];
void add(int u,int v)
{
nex[++edges]=hd[u],hd[u]=edges,to[edges]=v;
}
int get(int x)
{
return t[t[x].f].ch[1]==x;
}
int isrt(int x)
{
return !(t[t[x].f].ch[0]==x||t[t[x].f].ch[1]==x);
}
void pushup(int x)
{
t[x].minv=min(min(t[lson].minv,t[rson].minv), t[x].val);
t[x].maxv=max(max(t[lson].maxv,t[rson].maxv), t[x].val);
t[x].lmax=max(max(t[lson].lmax,t[rson].lmax),max(t[lson].maxv,t[x].val)-min(t[x].val,t[rson].minv));
t[x].rmax=max(max(t[lson].rmax,t[rson].rmax),max(t[rson].maxv,t[x].val)-min(t[x].val,t[lson].minv));
}
void marktag(int x,int v)
{
if(!x) return;
t[x].tag+=v,t[x].minv+=v,t[x].maxv+=v,t[x].val+=v;
}
void markrev(int x)
{
if(!x) return;
swap(t[x].lmax,t[x].rmax),swap(lson,rson),t[x].rev^=1;
}
void pushdown(int x)
{
if(t[x].tag)
{
marktag(lson,t[x].tag),marktag(rson,t[x].tag);
t[x].tag=0;
}
if(t[x].rev)
{
markrev(lson),markrev(rson);
t[x].rev=0;
}
}
void rotate(int x)
{
int old=t[x].f,fold=t[old].f,which=get(x);
if(!isrt(old)) t[fold].ch[t[fold].ch[1]==old]=x;
t[old].ch[which]=t[x].ch[which^1],t[t[old].ch[which]].f=old;
t[x].ch[which^1]=old,t[old].f=x,t[x].f=fold;
pushup(old),pushup(x);
}
void splay(int x)
{
int v=0,u=x,fa;
for(sta[++v]=u;!isrt(u);u=t[u].f) sta[++v]=t[u].f;
for(;v;--v) pushdown(sta[v]);
for(u=t[u].f;(fa=t[x].f)!=u;rotate(x))
if(t[fa].f!=u)
rotate(get(fa)==get(x)?fa:x);
}
void Access(int x)
{
for(int y=0;x;y=x,x=t[x].f)
splay(x),rson=y,pushup(x);
}
void makeroot(int x)
{
Access(x),splay(x),markrev(x);
}
void split(int x,int y)
{
makeroot(x),Access(y),splay(y);
}
void dfs(int u,int ff)
{
t[u].f=ff;
for(int i=hd[u];i;i=nex[i])
if(to[i]!=ff) dfs(to[i],u);
pushup(u);
}
int main()
{
// IO::setIO("input");
int i,j,n,q;
t[0].minv=inf,t[0].maxv=-inf;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&t[i].val);
for(i=1;i<n;++i)
{
int x,y;
scanf("%d%d",&x,&y),add(x,y),add(y,x);
}
dfs(1,0);
scanf("%d",&q);
for(i=1;i<=q;++i)
{
int a,b,v;
scanf("%d%d%d",&a,&b,&v);
split(a,b);
printf("%d\n",t[b].rmax);
marktag(b,v);
}
return 0;
}

  

bzoj 3999: [TJOI2015]旅游 LCT的更多相关文章

  1. bzoj 3999: [TJOI2015]旅游

    Description 为了提高智商,ZJY准备去往一个新世界去旅游.这个世界的城市布局像一棵树.每两座城市之间只有一条路径可 以互达.每座城市都有一种宝石,有一定的价格.ZJY为了赚取最高利益,她会 ...

  2. 【BZOJ3999】[TJOI2015]旅游(Link-Cut Tree)

    [BZOJ3999][TJOI2015]旅游(Link-Cut Tree) 题面 BZOJ 洛谷 题解 一道不难的\(LCT\)题(用树链剖分不是为难自己吗,这种有方向的东西用\(LCT\)不是方便那 ...

  3. [BZOJ - 2631] tree 【LCT】

    题目链接:BZOJ - 2631 题目分析 LCT,像线段树区间乘,区间加那样打标记. 这道题我调了一下午. 提交之后TLE了,我一直以为是写错了导致了死循环. 于是一直在排查错误.直到.. 直到我看 ...

  4. bzoj 2157: 旅游 (LCT 边权)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2157 题面; 2157: 旅游 Time Limit: 10 Sec  Memory Lim ...

  5. BZOJ 3999 旅游

    .......好长啊. #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  6. 【BZOJ2157】旅游 LCT

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

  7. [BZOJ 3282] Tree 【LCT】

    题目链接:BZOJ - 3282 题目分析 这道题是裸的LCT,包含 Link , Cut 和询问两点之间的路径信息. 写代码时出现的错误:Access(x) 的循环中应该切断的是原来的 Son[x] ...

  8. BZOJ.2816.[ZJOI2012]网络(LCT)

    题目链接 BZOJ 洛谷 对每种颜色维护一个LCT,保存点之间的连接关系. 修改权值A[x]和所有Max[x]都要改: 修改边的颜色先枚举所有颜色,看是否在某种颜色中有边,然后断开.(枚举一遍就行啊 ...

  9. bzoj 3779: 重组病毒 LCT+线段树+倍增

    题目: 黑客们通过对已有的病毒反编译,将许多不同的病毒重组,并重新编译出了新型的重组病毒.这种病毒的繁殖和变异能力极强.为了阻止这种病毒传播,某安全机构策划了一次实验,来研究这种病毒. 实验在一个封闭 ...

随机推荐

  1. C++11<functional>深度剖析:背景、原理、接口与实现

    自C++11以来,C++标准每3年修订一次.C++14/17都可以说是更完整的C++11:即将到来的C++20也已经特性完整了. C++11已经有好几年了,它的年龄比我接触C++的时间要长10倍不止吧 ...

  2. OpenCV学习笔记3

    OpenCV学习笔记3 图像平滑(低通滤波) 使用低通滤波器可以达到图像模糊的目的.这对与去除噪音很有帮助.其实就是去除图像中的高频成分(比如:噪音,边界).所以边界也会被模糊一点.(当然,也有一些模 ...

  3. Thymeleaf模板引擎与springboot关联后,在html中无法使用el表达式获取model存的值

    头部引入了thymeleaf <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thy ...

  4. MySQL多表关联查询数量

    //多表关联查询数量select user, t1.count1, t2.count2from user tleft join ( select user_id, count(sport_type) ...

  5. S3C2440 gpio + main

    相关文章:http://blog.csdn.net/zhangxuechao_/article/details/77990854 举例 start.S .globl _start _start: /* ...

  6. Swagger 接口文档规范

    导语: 相信无论是前端还是后端开发,都或多或少地被接口文档折磨过.前端经常抱怨后端给的接口文档与实际情况不一致.后端又觉得编写及维护接口文档会耗费不少精力,经常来不及更新.其实无论是前端调用后端,还是 ...

  7. Django的结构

    一.Django的结构 二.静态文件的配置 STATIC_URL = '/static/' # HTML中使用的静态文件夹前缀 STATICFILES_DIRS = [ os.path.join(BA ...

  8. javascript reduce 前端交互 总计

    sum(){ return this.products.reduce((total,next)=>{ return total + next.price * next.aumout},0) } ...

  9. ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded

    操作系统:Ubuntu 18.04 LTS 数据库:MySQL 5.7 执行了一次修改root用户密码的操作,修改完后退出了数据库,但是,当我在命令行中登录数据库(mysql -u root -p), ...

  10. 助教培训总结——熟练掌握GitHub及Git的使用方法

    一.Git 命令的理解和使用 1.使用git前需要建立一个本地仓库,用Git GUI Here的话就可以直接选择Create New Repository.Git Bash Here输入 命令git ...