Propagating tree Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 383C64-bit integer IO format: %I64d      Java class name: (Any)   Iahub likes trees very much. Recently he discovered an interesting tr…
标题效果: 有一棵树,有两种操作模式对本树:1:表示为(1 x val),在NOx加在节点上val,然后x每个节点加上儿子- val.给每个儿子一个儿子在一起-(- val),加到没有儿子为止.2:表示为(2 x)查询x节点上的值. 做法: 因为每次改动操作改动的并非一个值,而是非常多值.那我们将该题抽象成区间改动,点查询的问题.那怎么抽象呢?能够明确的是,每次操作尽管有加有减,可是每次做加法操作.或者减法操作的都是同一部分数(也就是说,在某次加上同一个数的节点们.下次操作一定是加上或者减去同样…
http://codeforces.com/problemset/problem/383/C 题目就是说,  给一棵树,将一个节点的值+val, 那么它的子节点都会-val, 子节点的子节点+val........这样类推, 给一系列操作,2是查询一个节点的值, 1是将一个节点的值+val. 首先,<dfs一遍求出dfs序以及每个点的深度, 然后建两颗线段树, 深度为奇数的建一棵, 偶数建一棵. 改变一个节点的值, 就把与他奇偶相同的那颗树全都+val, 不同的全都-val. 具体看代码>..…
按深度染色,奇深度的点存反权值. #include <bits/stdc++.h> using namespace std; vector <]; ],a[],s[],vis[],ind,n,m,src[],frm[],dep[]; void dfs(int p) { vis[p]=; frm[p]=ind+; ;i<g[p].size();i++) ) dep[g[p][i]]=dep[p]+, dfs(g[p][i]); seq[p]=++ind; } void build(i…
题意:题意很简单么,给定n个点,m个询问的无向树(1为根),每个点的权值,有两种操作, 第一种:1 x v,表示把 x 结点加上v,然后把 x 的的子结点加上 -v,再把 x 的子结点的子结点加上 -(-v),依次... 第二种:2 x, 表示查询 x 结点的权值. 析:因为这是一棵树,很难维护,所以可以考虑先用 dfs 记录每个结点的开始和结束的时间戳,而位于开始和结束时间戳内的就是就是它的子孙结点, 这样就能维护两棵线段树,一棵是奇数层的, 一棵是偶数层的,每次执行 1 操作就把相应的结点的…
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edg…
Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numbered from 1 to n with the root at vertex 1. For each vertex, t…
C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb…
C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb…
题目链接:点击传送 E. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consi…