Can anyone solve this? Problem G
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Can anyone solve this? Problem G
Name |
---|
If my understanding is correct the problem statement reduces to (assuming we can replace each node with an edge of the same weight)- Given a tree, find its diameter and there are updates that increase the weight of some edges? In that case, I don't understand why mod 1e9+7
I think you misunderstood the statement
I understand the statement as follows: You are given a tree with weights on edges ($$$b$$$) and vertices ($$$a$$$), calculate the sum over all pairs of vertices $$$\sum_i \sum_j \texttt{dist}(i, j) \cdot a_i \cdot a_j$$$. Queries may modify the weight of edges and vertices, and we have to report the value of the sum after each query.
If it is okay, then it can be solved with centroid decomposition in $$$\mathcal{O}((n + q) \log^2 n)$$$. When we modify the weight of a vertex $$$i$$$ we want to answer the sum $$$a_i \cdot \sum_i \texttt{dist}(i, j) \cdot a_j$$$, when we modify the weight of an edge $$$b_i$$$, we change the answer by a sum over $$$a_i$$$ in its subtree multiplied by the rest of weights. The latter can be done with one segment tree.
So we have to quickly answer, for a vertex, the sum of distances (multiplied by some coefficient) to all the other vertices. We keep the centroid decomposition, and for each subtree, in the decomposition, we keep a segment tree with distances from the root to the vertex, multiplied by the weight of the vertex. This requires some formulas, but we can update the weight of an edge (update on interval), the weight of a vertex (just one path to change), and query for the sum paths, which we need to answer when we change the weight of a vertex.
You can solve this problem here