题意:给一棵树,并给定各个点权的值,然后有3种操作:
I C1 C2 K: 把C1与C2的路径上的所有点权值加上K
D C1 C2 K:把C1与C2的路径上的所有点权值减去K
Q C:查询节点编号为C的权值

裸裸的树剖

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std; typedef long long LL; #define N 50010 struct Node
{
int to,next;
}e[N<<]; int id,cnt;
int head[N];
int num[N],siz[N],top[N],son[N];
int dep[N],pos[N],rank1[N],fa[N]; LL sum[N<<],add[N<<]; char s[]; int n,m,q;
int u,v;
int al,ar,ask; inline void init()
{
memset(son,-,sizeof(son));
memset(head,-,sizeof(head));
id=;
cnt=;
} void link(int x,int y)
{
e[++cnt]=(Node){y,head[x]};
head[x]=cnt;
} void dfs(int x,int father,int d)
{
siz[x]=;
dep[x]=d;
fa[x]=father;
for (int i=head[x];~i;i=e[i].next)
{
int t=e[i].to;
if (t!=fa[x])
{
dfs(t,x,d+);
siz[x]+=siz[t];
if (son[x]==- || siz[x]>siz[son[x]])
son[x]=t;
}
}
} void dfs2(int x,int cha)
{
top[x]=cha;
pos[x]=++id;
rank1[pos[x]]=x;
if (son[x]==-)
return ;
dfs2(son[x],cha);
for(int i=head[x];~i;i=e[i].next)
{
int t=e[i].to;
if(t!=son[x] && t!=fa[x])
dfs2(t,t);
}
} void pushup(int now)
{
sum[now]=max(sum[now<<],sum[now<<|]);
} void pushdown(int now,int m)
{
if (add[now])
{
add[now<<]+=add[now];
add[now<<|]+=add[now];
sum[now<<]+=add[now]*(m-(m>>));
sum[now<<|]+=add[now]*(m>>);
add[now]=;
}
} void build(int nowl,int nowr,int now)
{
add[now]=;
if (nowl==nowr)
{
sum[now]=num[rank1[nowl]];
return ;
}
int mid=(nowl+nowr)>>;
build(nowl,mid,now<<);
build(mid+,nowr,now<<|);
pushup(now);
} void update(int nowl,int nowr,int now,int L,int R,int d)
{
if (nowl>=L && nowr<=R)
{
add[now]+=d;
sum[now]+=d*(nowr-nowl+);
return ;
}
pushdown(now,nowr-nowl+);
int mid=nowl+nowr>>;
if (L<=mid) update(nowl,mid,now<<,L,R,d);
if (mid<R) update(mid+,nowr,now<<|,L,R,d);
pushup(now);
} int query(int nowl,int nowr,int now,int d)
{
int res();
if (nowl==nowr)
return sum[now];
pushdown(now,nowr-nowl+);
int mid=nowl+nowr>>;
if (d<=mid) res=query(nowl,mid,now<<,d);
else res=query(mid+,nowr,now<<|,d);
pushup(now);
return res;
} void work(int x,int y,int val)
{
while (top[x]!=top[y])
{
if (dep[top[x]]<dep[top[y]])
swap(x,y);
update(,n,,pos[top[x]],pos[x],val);
x=fa[top[x]];
}
if (dep[x]>dep[y])
swap(x,y);
update(,n,,pos[x],pos[y],val);
}
int main()
{
while (scanf("%d%d%d",&n,&m,&q)!=EOF && n+m+q)
{
init();
for (int i=;i<=n;i++)
scanf("%d",&num[i]);
for (int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
link(u,v);
link(v,u);
}
dfs(,,);
dfs2(,);
build(,n,);
while (q--)
{
scanf("%s",s);
if (s[]=='I')
{
scanf("%d%d%d",&al,&ar,&ask);
work(al,ar,ask);
}
else if (s[]=='D')
{
scanf("%d%d%d",&al,&ar,&ask);
work(al,ar,-ask);
}
else
{
scanf("%d",&ask);
printf("%d\n",query(,n,,pos[ask]));
}
}
}
return ;
}

【hdu3966】Aragorn's Story的更多相关文章

  1. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  2. 【原】谈谈对Objective-C中代理模式的误解

    [原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...

  3. 【原】FMDB源码阅读(三)

    [原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...

  4. 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新

    [原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...

  5. 【调侃】IOC前世今生

    前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...

  6. Python高手之路【三】python基础之函数

    基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object ...

  7. Python高手之路【一】初识python

    Python简介 1:Python的创始人 Python (英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种解释型.面向对象.动态数据类型的高级程序设计语言,由荷兰人Guido ...

  8. 【开源】简单4步搞定QQ登录,无需什么代码功底【无语言界限】

    说17号发超简单的教程就17号,qq核审通过后就封装了这个,现在放出来~~ 这个是我封装的一个开源项目:https://github.com/dunitian/LoTQQLogin ————————— ...

  9. 【原】FMDB源码阅读(二)

    [原]FMDB源码阅读(二) 本文转载请注明出处 -- polobymulberry-博客园 1. 前言 上一篇只是简单地过了一下FMDB一个简单例子的基本流程,并没有涉及到FMDB的所有方方面面,比 ...

随机推荐

  1. 阿里云 Django部署参考

    Linux下安装Python3和django并配置mysql作为django默认服务器 CentOS7.3安装Python3.6 yum except KeyboardInterrupt, e: 错误 ...

  2. 小程序input自动聚焦拉起键盘

    微信官方提供了两种自动聚焦的方法 1,auto-focus 接受boolean值:默认为false:只需设置为true即可 自动聚焦,拉起键盘:不过官方的提示即将废弃,所以能不用还是不要用 2,foc ...

  3. Django之CBV和FBV

    Django之CBV和FBV CBV和FBV是C和F的区别: C是Class,F是Function 在请求中,有GET请求和POST请求. 在写CBV时,url是可以对应一个类的,在类中,分别写出GE ...

  4. 集训第六周 数学概念与方法 数论 线性方程 I题

    Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...

  5. Swagger UI教程

    文档源地址 http://www.68idc.cn/help/makewebs/qitaasks/20160621620667.html Swagger-UI本身只提供在线测试功能,要集成它还需要告诉 ...

  6. <c:foreach> 标签获取循环次数

    <c:forEach var="i" begin="1" end="9" varStatus="status"&g ...

  7. C51 蜂鸣器 个人笔记

    音调:频率 音量:高低电平占空比 有源:上面没有加号,只需高低电平即可发声 无源:上面有加号,不仅要电平,还要, 的频率 这里的有源不是指电源的"源",而是指有没有自带震荡电路,有 ...

  8. 慕课笔记利用css进行布局【混合布局练习】

    通过学习div的布局,以一个简单的内容管理网站的布局为例子,用div+css进行简单的网页布局,加深学印象: <html> <head> <title>CSS+di ...

  9. BNUOJ 6023 畅通工程续

    畅通工程续 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 1874 ...

  10. [TyvjP1313] [NOIP2010初赛]烽火传递(单调队列 + DP)

    传送门 就是个单调队列+DP嘛. ——代码 #include <cstdio> ; , t = , ans = ~( << ); int q[MAXN], a[MAXN], f ...