Codeforce 383C. Propagating tree
来源:互联网 发布:东北林业大学 知乎 编辑:程序博客网 时间:2024/04/29 21:28
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn=210000;vector<int> g[maxn];int n,m;int l[maxn],r[maxn];int coeff[maxn];int init[maxn];int deep;int dfs(int u,int pre,int c){ l[u]=deep; coeff[u]=c; for(auto& v : g[u]) { if(v==pre) continue; deep++; dfs(v,u,-c); } r[u]=deep;}int lowbit(int x) { return x&(-x); }int tree[maxn];void add(int p,int v){ for(int i=p;i<=n;i+=lowbit(i)) tree[i]+=v;}int sum(int v){ int ans=0; for(int i=l[v];i>0;i-=lowbit(i)) ans+=tree[i]; return ans;}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",init+i); } for(int i=0;i<n-1;i++) { int u,v; scanf("%d%d",&u,&v); g[u].push_back(v); g[v].push_back(u); } deep=1; dfs(1,0,1); while(m--) { int cmd,x,y; scanf("%d%d",&cmd,&x); if(cmd==1) { scanf("%d",&y); int v=coeff[x]*y; add(l[x],v); add(r[x]+1,-v); } else { int ans=sum(x); printf("%d\n",init[x]+coeff[x]*ans); } } return 0;}
1 0
- Codeforce 383C. Propagating tree
- CodeForces 383C Propagating tree
- codeforces 383C Propagating tree
- CODEFORCES, 383C,Propagating tree
- Codeforces 383C Propagating tree(树状数组)
- 【CodeForces】383C Propagating tree 线段树
- Codeforces 383C Propagating tree 题解&代码
- Codeforces 383C Propagating tree(树状数组)
- Codeforces 383C Propagating tree DFS序+BIT
- CF 383C Propagating tree(dfs序+线段树)
- Codeforces 383C Propagating tree(树状数组)
- CodeForces - 383C Propagating tree(dfs + 线段树)
- Codeforces 383C . Propagating tree【树状数组,dfs】
- CF 383C Propagating tree [想法+树状数组]
- CodeForces 383C Propagating tree 树上哈希+树状数组
- 383C - Propagating tree 线段树加时间戳
- Codeforces 383C Propagating tree(树状数组)
- Codeforces Round #225 (Div. 1)-C. Propagating tree(线段树)
- 制作动态及静态Framework
- HTTP协议 常用 总结
- 深入理解Java内存模型(三)——顺序一致性
- 如何检测您的浏览器是否支持HTML5视频
- 关于24点游戏的编程思路与基本算法
- Codeforce 383C. Propagating tree
- ps 红眼工具 将拍照片时出现的红眼消除
- 深入理解Java内存模型(二)——重排序
- uploadify 请求错误的问题
- 解决jquery.uploadify上传插件导致google崩溃
- setTimeout 中的 参数 调用函数 是字符串形式
- 深入理解Java内存模型(一)——基础
- 日语学习之沪江N4基础 20141126 -4
- string转LPCSTR