yosupo06 / library-checker-problems

The problem data (Test case generator, judge's solution, task, ...) of Library Checker
https://judge.yosupo.jp/
Apache License 2.0
517 stars 117 forks source link

[Problem proposal] Vertex Add Range Contour Max on Tree #1122

Closed lrvideckis closed 6 months ago

lrvideckis commented 6 months ago

Problem name: Vertex Add Range Contour Max on Tree

Problem

Given a tree with N vertices, where the i-th edge connects vertices ui​ and vi​. Value ai​ is written on the vertex i. Process the following Q queries in order:

Constraint

same as https://judge.yosupo.jp/problem/vertex_add_range_contour_sum_on_tree

Solution / Reference

edge centroid decomposition

https://codeforces.com/blog/entry/104997 https://codeforces.com/blog/entry/120446

(Optional) Note / Disucussion

edge CD is possible in O(n log^2 n): there's only 2 childs in each decomposition, so you just query the [l,r) range in the other child

https://github.com/programming-team-code/programming_team_code/blob/main/trees/edge_centroid_decomp/contour_range_query.hpp

normal CD is possible in O(n log^3 n) with like a 2d structure like mergesort/wavelet tree to handle querying all childs in suffix, and of certain depth range

cameroncuster commented 6 months ago

dang this is clean ^^^

noshi91 commented 6 months ago

Edge CD was previously discussed when the sum version was added, and it was concluded that the sum version is better for checking the correctness of not only normal CD but also edge CD. see https://github.com/yosupo06/library-checker-problems/issues/816 (I'm sorry for the conversation being in Japanese.)