调了恒久突然发现输出优化忘记带负号了..

就是差分树状数组维护Dfs序即可。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std; inline void Get_Int(LL &x)
{
x=; char ch=getchar(); LL f=;
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();} x*=f;
}
inline void Put_Int(LL x)
{
char ch[]; LL top=;
if (x<) putchar('-'),x=-x;
if (x==) ch[++top]='';
while (x) ch[++top]=x%+'',x/=;
while (top) putchar(ch[top--]); putchar('\n');
}
//=============================================
const LL Maxn=;
LL Begin[Maxn],End[Maxn],c[Maxn],cv[Maxn],a[Maxn];
LL head[Maxn],dep[Maxn];
bool vis[Maxn];
LL u,v,w,n,m,Type,cnt,tot;
struct Edge{LL to,next;}edge[Maxn<<];
inline LL lowbit(LL x) {return x&(-x);}
struct BIT
{
LL c[Maxn];
inline void Add(LL x,LL v) {for (LL i=x;i<=n;i+=lowbit(i)) c[i]+=v;}
inline LL Sum(LL x) {LL ret=; for (LL i=x;i;i-=lowbit(i)) ret+=c[i]; return ret;}
inline void Interval(LL x,LL y,LL w) {Add(x,w),Add(y+,-w);}
}Bit1,Bit2;
inline void AddE(LL u,LL v)
{edge[cnt].to=v;edge[cnt].next=head[u];head[u]=cnt++;} void Dfs(LL u)
{
Begin[u]=++tot; vis[u]=true;
for (LL i=head[u];i!=-;i=edge[i].next)
if (!vis[edge[i].to])
dep[edge[i].to]=dep[u]+,Dfs(edge[i].to);
End[u]=tot;
} inline void Modify_Point()
{Get_Int(u),Get_Int(w);Bit1.Interval(Begin[u],End[u],w);}
inline void Modify_Tree()
{Get_Int(u),Get_Int(w);Bit1.Interval(Begin[u],End[u],(-dep[u])*w);Bit2.Interval(Begin[u],End[u],w);}
inline LL Query()
{Get_Int(u);return Bit1.Sum(Begin[u])+Bit2.Sum(Begin[u])*dep[u];} int main()
{
Get_Int(n),Get_Int(m);
for (LL i=;i<=n;i++) Get_Int(a[i]);
memset(head,-,sizeof(head)); tot=;
for (LL i=;i<n;i++)
Get_Int(u),Get_Int(v),AddE(u,v),AddE(v,u);
memset(vis,false,sizeof(vis)); Dfs();
for (LL i=;i<=n;i++) Bit1.Interval(Begin[i],End[i],a[i]);
for (LL i=;i<=m;i++)
{
Get_Int(Type);
if (Type==) Modify_Point();
if (Type==) Modify_Tree();
if (Type==) Put_Int(Query());
}
return ;
}

C++

最新文章

  1. Sybase 常用SQL
  2. maven 依赖
  3. ctype.h库函数----字符操作函数
  4. 免费素材:包含 250+ 组件的 DO UI Kit
  5. JS中关于比较运算符的问题(a===b)
  6. define宏定义中的#,##,@#及\符号
  7. 一步步学习NHibernate(7)——HQL查询(1)
  8. c# 捕捉键盘按键
  9. jQuery开发技术笔记
  10. webapp 1px显示两倍的问题
  11. scrapy_Response and Request
  12. iOS CATransition 自定义转场动画
  13. Oracle 11g OGG 修改 trail 文件大小
  14. HDU 1431 素数回文 离线打表
  15. linux 查看机器内存方法 (free命令)
  16. java反射知识点总结
  17. Java日期格式化参数对照表
  18. B - GuGuFishtion(莫比乌斯 欧拉函数 预处理mu函数的欧拉函数的模板)
  19. 你所不知道的,Java 中操作符的秘密?
  20. Linux下用户管理、目录结构

热门文章

  1. php 全角半角转换
  2. Walls(floyd POJ1161)
  3. CSS 盒子模型概述
  4. [转]C#读写TEXT文件
  5. spring schedule
  6. 初识DeepLearning4j
  7. 深入浅出设计模式——命令模式(Command Pattern)
  8. List怎么遍历删除元素
  9. OpenGL的API函数使用手册
  10. $inArray()总是返回-1