๐ WAYPOINT LESSON
Contest Scan โ Trees and Strings Edition
โญโญโญ advancedโณ 25 min read๐ Lesson 195 of 281
Tree statements advertise their family through query shape; string statements through what repeats.
Reading trees and strings fast
A tree with q queries on paths = LCA family. If values never change, root-distance prefixes + LCA finish it; updates push you to HLD or Euler + BIT on subtrees. "For every node" output = one postorder DFS; if the answer for a child's parent depends on the child, it is tree DP.
A string asking "what repeats" = borders and failure functions. The KMP failure array answers period, borders, and occurrence counting in one preprocessing pass. If the question is "how many distinct", expect suffix structures or hashing instead.